Log in

View Full Version : dynamic thumbnail pointer



nortski
08-12-2010, 07:43 PM
Hi all, completely new at this and have got myself stuck!

I am trying to display a thumbnail image by connecting to my database and retrieving the URL that points to the image.

I know that the connection is working but I can't seem to get it to point to the image. Probably something really simple. Here's my code:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Image Swap Using CSS</title>
<style type="text/css">

body {
margin: 0;
padding: 0;
background-color:#000000;
}

img {
margin: 0;
padding: 0;
border: none;
}

.test {
margin: 0;
padding: 0;
width: 99px;
height: 130px;
}

.test a:hover img {
visibility:hidden;
}

</style>
</head>

<body>
<?php
// connect to the database
mysql_connect("********", "****") or die(mysql_error());
mysql_select_db("eliteescorting") or die(mysql_error());
$start=0;

// expand on the searches
$data=mysql_query("SELECT * FROM escorts WHERE base = 'manchester' ORDER BY RAND()");
$num_results=@mysql_num_rows($data);

for($ii = $start;$ii < $num_results; $ii++){
?>
<div class="test"><a href="#"><img src="<?php echo $data[$ii]['thumb'];?>" /></a></div>
<?php } ?>
</body>

</html>


In my mySQL field 'thumb' contains the full URL of the image ie http://www............

This is just for testing, I'll get round to sorting out security issues later.

Your help will be greatly appreciated! :)

Regards,
Nortski.

Schmoopy
08-13-2010, 05:18 PM
Best way to do this is not to use a for loop, but a while loop, and use mysql_fetch_array():



<?php
if($num_results) {

while($img = mysql_fetch_array($data)) {
?>
<div class="test"><a href="#"><img src="<?php echo $img['thumb']; ?>"></a></div>
<?php
}

}
?>


Hope this helps.