954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

add hyperlink to mysql results in php

Hello,
I am trying to add hyperlink to my mysql query result. I have a table called EastLondon which consist of the following:

(restaurant_id INT UNSIGNED PRIMARY KEY, restaurant_name VARCHAR(20), phone_number VARCHAR(20), picture varchar(8), website varchar(40));


I extract all these info into a table using php. What I want to do is add the actual hyperlink to 'website' results. I have the following code but it doesn't work:

foreach ( $restaurants as $row ) {
               echo '<table width="400" border="1" cellspacing="2" cellpadding="2">';
echo '<tr><th width="200">Restaurant Name  </th>';
echo '<td width="200">'.$row['restaurant_name'].'</td></tr>'; 
echo '<tr><th width="200">Telephone Number </th>';
echo '<td width="200">'.$row['phone_number'].'</td></tr>';
echo '<tr><th width="200"><img src="./image/'.$row["picture"].'" width="100" height="131" ></th>';
echo '<a href="'.$row['website'].'">'.$row['website'].'</a>';

echo '</table>';
            }
zynap
Newbie Poster
3 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

try this in your last lines of your code

echo '<tr><td><th width="200"><img src="./image/'.$row["picture"].'" width="100" height="131" ></th>';
echo '<a href="'.$row['website'].'">'.$row['website'].'</a></td></tr></table>';


and review your URL addresses in your data base, maybe they aren't right

Nick Nitro
Newbie Poster
1 post since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

I actually tried that code before and it still doesn't work. In order to make sure that the URL works, I used http://www.google.com in my database, but it says that the page can't be found when i click on the url. I've been searching for the answer to this for more than 3 days and I can't find it anywhere. I appreciate any kind of help. Thanks

zynap
Newbie Poster
3 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

In what way does it "not work". What are the values of the row (what is the exact value of [icode]$row['website'][/code]

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 
In what way does it "not work". What are the values of the row (what is the exact value of [icode]$row['website'][/code]

I think that the browser looks for the URL in the server because it says that the page cannot be found. The exact value that is inserted into the database is:[icode]'http://www.google.com'[/code]

I can retrieve the address but still I can't reach it.

zynap
Newbie Poster
3 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

If in the database it says http://www.google.com then the code

echo '<a href="'.$row['website'].'">'.$row['website'].'</a>';

should produce

<a href="http://www.google.com">http://www.google.com</a>


Look at the source (CTRL+U in Firefox) and see if that is what it is producing

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You