boney alex Posted April 29, 2007 Share Posted April 29, 2007 Hi, Im trying to print out a table of vehicle information. Each vehicle record has an image (picture of the vehicle) associated with it. I have named each image the ID of the makemodel. Ive got a while loop which runs through the records and prints them out in a table, but Im struggling to display the image for each record. <table width="300" border="0" cellspacing="10"> <? while ($van = mysql_fetch_array($query)) { $makemodelID = $van['MakeModelID']; $make = $van['Make']; $model = $van['Model']; $spec = $van['Specification']; $vantype = $make. " " .$model. " " .$spec; $loadoptions = $van['Load_Options']; $engine = $van['Engine']; $extras = $van['Extras']; echo (" <tr> <td>Van:</td> <td>$vantype</td> <td rowspan="4"><img src="Images/$makemodelID.gif"></td> </tr> <tr> <td>Load Options:</td> <td>$loadoptions</td> </tr> <tr> <td>Engine:</td> <td>$engine</td> </tr> <tr> <td>Extras:</td> <td>$extras</td> </tr>"); } ?> </table> Obviously the problems lies somewhere around this line of code: <td rowspan="4"><img src="Images/$makemodelID.gif"></td> Any hints/ideas? Thank you. Link to comment https://forums.phpfreaks.com/topic/49212-solved-problem-displaying-an-image/ Share on other sites More sharing options...
fireice87 Posted April 29, 2007 Share Posted April 29, 2007 Hey im new to php myself but i can help you with this a bit. For php to be able to display an image you need to set the header to the file type for example....header("Content-Type: image/jpeg"); Im not sure if this allows you to display multiple images on a page it deffenitly wont if the images are of diffrent file types. If you need to display multiple images you may need to write the image display code on a seperate php page and link to that page as the image source. are you getting any erros? or are the images just not displaying? hope that helps a bit Link to comment https://forums.phpfreaks.com/topic/49212-solved-problem-displaying-an-image/#findComment-241151 Share on other sites More sharing options...
RoninStretch Posted April 29, 2007 Share Posted April 29, 2007 Im noob too and i don't know what the last guy was on about but from where I sit it just looks like you've mixed your php+html code. You're echoing the whole thing so the variable here... <img src="Images/$makemodelID.gif"></td> is acting as html... check the source of your page and see i bet its trying to show an called images/$makemodelID.gif. Also I don't know how your page is working at all... double quotes need an escape before them or php thinks you are trying to end your echo statement. so all " in the echo need to have be \" instaed all apart from the " that ends the echo statement... So lets try this, stopping the echo, using normal php code to enter the varible and then back to an echo to finish up the <IMG tag.. I know there are ways to do this better/simpler but i dont know them yet <table width="300" border="0" cellspacing="10"> <? while ($van = mysql_fetch_array($query)) { $makemodelID = $van['MakeModelID']; $make = $van['Make']; $model = $van['Model']; $spec = $van['Specification']; $vantype = $make. " " .$model. " " .$spec; $loadoptions = $van['Load_Options']; $engine = $van['Engine']; $extras = $van['Extras']; echo (" <tr> <td>Van:</td> <td>$vantype</td> // we end the <IMG tag exactly where the variable name needs to go.. <td rowspan=\"4\"><img src=\"Images/"; // echo the variable seperatly echo $makemodelID; //and finish up the IMG tag. echo ".gif\">"; // and carry on.. echo (" </td> </tr> <tr> <td>Load Options:</td> <td>$loadoptions</td> </tr> <tr> <td>Engine:</td> <td>$engine</td> </tr> <tr> <td>Extras:</td> <td>$extras</td> </tr>"); } ?> </table> Link to comment https://forums.phpfreaks.com/topic/49212-solved-problem-displaying-an-image/#findComment-241161 Share on other sites More sharing options...
Barand Posted April 29, 2007 Share Posted April 29, 2007 Easier just to use single quotes echo (" <tr> <td>Van:</td> <td>$vantype</td> <td rowspan="4"><img src='Images/$makemodelID.gif'></td> </tr> ..... "); or escaped double quotes echo (" <tr> <td>Van:</td> <td>$vantype</td> <td rowspan="4"><img src=\"Images/$makemodelID.gif\"></td> </tr> ..... "); Link to comment https://forums.phpfreaks.com/topic/49212-solved-problem-displaying-an-image/#findComment-241163 Share on other sites More sharing options...
RoninStretch Posted April 29, 2007 Share Posted April 29, 2007 See, easier way.. Knew it. Link to comment https://forums.phpfreaks.com/topic/49212-solved-problem-displaying-an-image/#findComment-241166 Share on other sites More sharing options...
fireice87 Posted April 29, 2007 Share Posted April 29, 2007 lol yeah think i was on a completly diffrent track with this one ignore me Link to comment https://forums.phpfreaks.com/topic/49212-solved-problem-displaying-an-image/#findComment-241167 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.