Forum Moderators: coopster

Message Too Old, No Replies

Anchor image from database

How to anchor an image from a database mysql

         

Dawn

12:27 pm on Dec 13, 2007 (gmt 0)

10+ Year Member



Hi guys,

I have this script which works fine for me so I do not want to change it as I'm not sure what I doing and it's taken me this long to get this far.

Does anyone know how I get the image to link onto another page when clicked. I think I have to change something in the table on my database. Any suggestions please. My images are stored on my databases under the path name so http://example.com/images I've tried adding an <a href to that but didn't work - I know that's probably a stupid thing to do! Here's my script;

Thanks everyone;

<?php
$sql = "SELECT * FROM VillaCatalog WHERE villaType = 'one bedroom'";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td><img src =\"". $row['pix']."\"></td>";
echo "<td>".$row['villaName']."</td>";
echo "<td>".$row['villaDescription']."</td>";
echo "<td>".$row['villaCity']."</td>";
echo "<td>".$row['villaID']."</td>";
echo "</tr>";
}
?>
</table>

[edited by: dreamcatcher at 1:05 pm (utc) on Dec. 13, 2007]
[edit reason] use example.com / thanks [/edit]

deMorte

12:44 pm on Dec 13, 2007 (gmt 0)

10+ Year Member



Hello and welcome.

Does each image link to a same page or a different page? I'm guessing a different page?

If that is the case, you could probably add a column "url" on the VillaCatalog table and put the url there. After this you can add the basic <a href=> on your code as such:


<?php
$sql = "SELECT * FROM VillaCatalog WHERE villaType = 'one bedroom'";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td><a href=".$row['url']."><img src =\"". $row['pix']."\"></a></td>";
echo "<td>".$row['villaName']."</td>";
echo "<td>".$row['villaDescription']."</td>";
echo "<td>".$row['villaCity']."</td>";
echo "<td>".$row['villaID']."</td>";
echo "</tr>";
}
?>
</table>

Hope this helps.

Dawn

3:30 pm on Dec 13, 2007 (gmt 0)

10+ Year Member



Thank you very much that works perfectly!