Jump to content

Displaying images


MA06

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.
Link to comment
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.
Link to comment
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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.