nortksi Posted August 12, 2010 Share Posted August 12, 2010 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. Link to comment https://forums.phpfreaks.com/topic/210582-dynamic-thumbnail/ Share on other sites More sharing options...
wildteen88 Posted August 12, 2010 Share Posted August 12, 2010 mysql_query only returns a result resource. In order to retrieve the results from the query, you'll need to use one the mysql_fetch_*() functions, for example mysql_fetch_assoc. Example php code $query = 'SELECT thumb FROM escorts WHERE base = 'manchester' ORDER BY RAND()'; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo $row['thumb'] . '<br />'; } Link to comment https://forums.phpfreaks.com/topic/210582-dynamic-thumbnail/#findComment-1098628 Share on other sites More sharing options...
nortksi Posted August 12, 2010 Author Share Posted August 12, 2010 Thx wildteen88, knew it was something daft! I used: if ($num_results > 0) { while($result = mysql_fetch_array($data)) $dr [] = $result; } Thanks for pointing me in the right direction! Regards, Nortski. Link to comment https://forums.phpfreaks.com/topic/210582-dynamic-thumbnail/#findComment-1098634 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.