Dynamic link on image?

Discussion in 'PHP' started by pictureboarduk, Apr 10, 2010.

  1. #1
    Hi,

    I am trying to add a link to some images but I'm stuck trying to figure out the syntax.

    Here is what I've wrote:

    
    <?php
    	$query = "SELECT * from products LIMIT 0, 3";
    	$result = mysql_query($query) or die(mysql_error());
    	echo '<table>';
    	echo "<tr>";
    	while($row = mysql_fetch_object($result))
    	{
    		$id = $row->product_ID;
    		$picture = substr($row->product_Picture, 3);
    		$description = $row->product_Title;
    		$price = $row->product_SalePrice;
    					
    		echo "<td>";
    		/********************************
    				//HERE IS THE LINK :
    		********************************/
    		echo "<img src='". $picture ."' href='productpage.php?id=<?php echo $id; ?>' />";
    		echo "<br />";
    		echo $description;
    		echo "<br />";
    		echo $price;
    		echo "<br />";
    		echo "<td>";
    	}
    	echo "</tr>";
    	echo '</table>';
    ?>
    
    Code (markup):
    The images from the query display, but they are not 'clickable'.


    I'm trying to make so that if someone clicks on the products image, they will be taken to that products page, but I'm stuck trying to figure out how to form the link.

    Can anyone help me with this?

    Your help would be most appreciated!

    Thanks!
     
    pictureboarduk, Apr 10, 2010 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    echo '<a href="productpage.php?id='.$id.'"><img src="'.$picture.'" /></a>';
    PHP:
     
    JAY6390, Apr 10, 2010 IP
    pictureboarduk likes this.
  3. pictureboarduk

    pictureboarduk Well-Known Member

    Messages:
    551
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Arr thats brilliant Jay!

    Thanks ever so much buddy, really appreciate it! :) :)
     
    pictureboarduk, Apr 10, 2010 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    No problem
     
    JAY6390, Apr 10, 2010 IP