Hi
I'm having problems with putting an image - outofstock.gif into a table cell but only if prod_status == 'Sold'
An empty image place holder shows - but without the actual image in it.

Ideally I also wanted this whole table column to be a background to another table cell (and not in a separate column) but couldn't get that to work either.

I know something like <td background='image/outofstock' but couldn't get the if statement to work within the background setting?

<td align="center"><img src="<?php if ($row_rs_dresses['prod_status'] == "Sold") $src = 'images/outofstock.gif'; else echo 'images/dot.gif'?>" width="40" height="40" /></td>

Any ideas would be great :-)
Many thanks!

Recommended Answers

All 6 Replies

Well if you are showing a image with a if statement it would be something like this;

$var = "10";

if ($var > 5) {
echo "put image tag hear";
{ 

else {
echo " $var is not grater that 5";
}

@evanburry,

Try changing this part of you codes

$src = 'images/outofstock.gif';

To this

echo 'images/outofstock.gif';

As veedeoo said, or try putting the if statement outside your img tags

<?php if $row_rs_dresses['prod_status'] == "Sold") { ?>
<img src="images/outofstock.gif" width="40" height="40" />
<?php } else { ?>
<img src="images/dot.gif" width="40" height="40" />
<?php } ?>

Hi Guys
That works perfectly! Thanks. Really appreciate the responses and help.

I have just one more question:
Is it possible to put all that into a <td background=...</td
So that I can have the image show up as a background in a table cell, with my normal text on top of it?

Many thanks

You could put it into a div or class instead of the table (I can't answer your question as it is years since I put a background image set to a table cell).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.