Jump to content


Photo

Displaying images


  • Please log in to reply
6 replies to this topic

#1 MA06

MA06
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 11 April 2006 - 07:24 PM

Hi all,

I have some images in an images folder, which i have titled the same as primary keys in a products table.

e.g. image name= "001". ID in a mySQL table = 001.

What i want to do is display all images with their related fields in a table. I have not managed to do this so far, here is what i got. Everything else displays except the images.

echo "<TABLE border=1 cellpadding=5>";
echo "<TR><TD></TD><TD>Name</TD><TD>Price</TD><TD>Description</TD></TR>";

//Loop and format the data in a HTML table
while($newArray=mysql_fetch_array($result))
    {

        $Name = '<img src=\'images/'.($result['ID']).'.jpg\' border=0 />';

    $Field1=$newArray[$Name ];
    $Field2=$newArray['Name'];
    $Field3=$newArray['Price'];
    $Field4=$newArray['Description'];
    echo "<TR><TD> $Field1 </TD><TD> $Field2 </TD><TD> $Field3 </TD><TD> $Field4 </TD></TR>";
    }

Thanks in advance for any help.

MA.

#2 MA06

MA06
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 11 April 2006 - 10:35 PM

Hi guys,

The problem seems to be with this line: $Name = '<img src=\'images/'.($result['ID']).'.jpg\' border=0 />'; The thing is it displays the table with the details i.e. name, price and description but not the associated image, also no error is given. The images are all JPEG's and each name of an image is the same as the id field in a mysql table which is the primary key of the table.

Any ideas in what i may be doing wrong, or any solutions,

Thanks,

MA.

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 April 2006 - 11:03 PM

Unless I'm missing something, there isn't anything in your code to actually echo the value $Name, i.e. the image tag itself, ergo no image gets displayed.
Legend has it that reading the manual never killed anyone.
My site

#4 MA06

MA06
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 12 April 2006 - 12:01 AM

Hi Andy,

Thanks for the reply the thing is i could not figure out how to put the image code within the table as when i try to place the code echo "$Name = '<img src=\'images/'.($result['ID']).'.jpg\' border=0 />'"; i get an error. So i tried to get a variable $Name to equal getting the image and then displaying that variable within the table as $Field1.

How can i write it within an echo statement, thank you

MA.



#5 Bhaal

Bhaal
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 12 April 2006 - 01:03 AM

Wouldn't you have to put just the name of the image in the variable $name then

echo "<img src=\"../PATH/TO/IMAGE/$name\">";

Dunno - I'm just a noob as well.

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 12 April 2006 - 02:37 AM

It looks as though this should work. If it generates no syntax error but doesn't show the image, view the actual html source generated since that should give you the clue(s) needed to get the syntax correct:
$img = "<img src='images/". $result['ID']. ".jpg' border='0'/>";
echo $img;

Legend has it that reading the manual never killed anyone.
My site

#7 MA06

MA06
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 12 April 2006 - 01:18 PM

Result! Thanks guys the problem was it was not reading the id field from the table, iviewedthe source on the html page and the there was a blank before the .jpg. So i defined a variable $Field1 to equal the id and then placed the variable in the previous code:

while($newArray=mysql_fetch_array($result))
$Field1=$newArray['ID'];
$img = "<img src='images/". $Field1. ".jpg' border='0'/>";
echo $Field1;

MA.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users