Re: displaying hyperlinks in MySQL query results
| From: | Fredrik de Vibe | Date: | Fri, 21 Feb 2003 02:37:08 +0000 |
| Subject: | Re: displaying hyperlinks in MySQL query results | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-25811@lists.php.net to get a copy of this message | ||
krutec@easystreet.com (Rick Tucker) writes:
[ snip ]
> The first 3 columns return perfectly. The Vendor URL data, on the other
> hand, is returned as text, rather than hyperlinks. I've tried tweaking the
> code several different ways with no success.
>
> The following code is what I started with. It returns everything I need.
> The HTML table is formatted correctly. I thought I could use a 'hypertext'
> datatype in MySQL, but from what I see there isn't any such datatype. And
> I'm so new to PHP I don't know how to isolate the Vendor URL field and
> convert the results to links. Any help would be appreciated.
[ snip ]
A hyperlink (such as you speak of) is an HTML construct. You can save
one as text in a database, but the contents of the database are still
text. It can be interpreted as hyperlinks by a web browser, but then
it must contains <a>-tags (or similar).
This is as such not really neither a php nor a mysql issue. When you
print the url field, you have to print the html tag you need as well,
like you have done with the other tags you use (<table>, <td> and so
on). eg. printf("<a href=\"%s\">%s</a>", $url, $url);
http://www.blooberry.com/indexdot/html is a
nice html resource.
Also, mysql_fetch_array($result) is easier to use, as it gives you an
associative array, you don't need the indexes and it doesn't give much
overhead (or at least, it's not supposed to). I wouldn't use a
foreach() construct in your case, either, it's easier (and should be
more efficient) to use something like
printf("<tr><td>%s</td><td>%s</td></tr>\n",
$data[0], $data[1]);
and so on.
--
--Fredrik
... and furthermore ... I don't like your trousers.