Jump to content

Archived

This topic is now archived and is closed to further replies.

MA06

Displaying images

Recommended Posts

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.

[code]
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>";
    }
[/code]

Thanks in advance for any help.

MA.

Share this post


Link to post
Share on other sites
Hi guys,

The problem seems to be with this line:[b] $Name = '<img src=\'images/'.($result['ID']).'.jpg\' border=0 />';[/b] 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 [b]echo "$Name = '<img src=\'images/'.($result['ID']).'.jpg\' border=0 />'"; [/b] i get an error. So i tried to get a variable[b] $Name[/b] to equal getting the image and then displaying that variable within the table as [b]$Field1.[/b]

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

MA.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:
[code]$img = "<img src='images/". $result['ID']. ".jpg' border='0'/>";
echo $img;[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.