MA06 Posted April 11, 2006 Share Posted April 11, 2006 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 tablewhile($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. Quote Link to comment https://forums.phpfreaks.com/topic/7133-displaying-images/ Share on other sites More sharing options...
MA06 Posted April 11, 2006 Author Share Posted April 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7133-displaying-images/#findComment-26011 Share on other sites More sharing options...
AndyB Posted April 11, 2006 Share Posted April 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7133-displaying-images/#findComment-26021 Share on other sites More sharing options...
MA06 Posted April 12, 2006 Author Share Posted April 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7133-displaying-images/#findComment-26040 Share on other sites More sharing options...
Bhaal Posted April 12, 2006 Share Posted April 12, 2006 Wouldn't you have to put just the name of the image in the variable $name thenecho "<img src=\"../PATH/TO/IMAGE/$name\">";Dunno - I'm just a noob as well. Quote Link to comment https://forums.phpfreaks.com/topic/7133-displaying-images/#findComment-26052 Share on other sites More sharing options...
AndyB Posted April 12, 2006 Share Posted April 12, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/7133-displaying-images/#findComment-26067 Share on other sites More sharing options...
MA06 Posted April 12, 2006 Author Share Posted April 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7133-displaying-images/#findComment-26199 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.