Results 1 to 2 of 2

Thread: dynamic thumbnail pointer

  1. #1
    Join Date
    Aug 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default dynamic thumbnail pointer

    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:

    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.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Best way to do this is not to use a for loop, but a while loop, and use mysql_fetch_array():

    PHP Code:
    <?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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •