Display images when URL to image is in a database problem.

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

  1. #1
    Hi,

    I have in my database the location of some images I want to display, all formatted as:

    I'm trying to diplay them in a webpage but get the following error:

    The 'x's display fine, matching the number of row in the database, but the images do not.

    Here is my code:

    
    <?php
    $query = "SELECT product_Picture from products LIMIT 0, 10";
    $result = mysql_query($query) or die(mysql_error());
    $x=0;
    while($row = mysql_fetch_array($result))
    {
    	echo 'x';//these work
    	$row[x] = substr($row, 3);//removes the leading .. from the stored URLs
    	echo "<img src='".$row."' /><br />";
    }
    ?>
    
    Code (markup):
    Can anyone help me correct this problem?

    Your help would be most appreciated!

    Thanks!
     
    pictureboarduk, Apr 9, 2010 IP
  2. ThomasTwen

    ThomasTwen Peon

    Messages:
    113
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    use the following code instead:

    
    <?php
    $query = "SELECT product_Picture from products LIMIT 0, 10";
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_object($result))
    {
    	$link = substr($row->product_Picture, 3);
    	echo "<img src='". $link ."' /><br />";
    }
    ?>
    
    PHP:
     
    ThomasTwen, Apr 9, 2010 IP
    pictureboarduk likes this.
  3. pictureboarduk

    pictureboarduk Well-Known Member

    Messages:
    551
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Oh man thanks soooo much!

    Works perfectly. I'm gonna look into the use of the arrow, I was stumped by this problem for ages.

    Thanks again buddy!

    :)
     
    pictureboarduk, Apr 9, 2010 IP