Jump to content

[SOLVED] Problem Displaying an Image


boney alex

Recommended Posts

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

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

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 :P

 



<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> 

 

 

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>

.....
");

Archived

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

×
×
  • 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.