PDA

View Full Version : If / Else statments with images


kona72
04-12-2006, 05:58 AM
Hi all,

I have some thumbnail being generated form the database but i need a way to have it display a default image if the image hasn;t been uploaded yet or if there is no image.

Here is the code generating the image right now

<tr align="left" valign="top">
<td width="250" rowspan="2">

/picgallery/<?php echo $row_rsLandscapes['thumbs']; ?></p>


Full Size</p></td>
<td width="210" class="main_text"><span class="large_bold"><?php echo $row_rsLandscapes['title']; ?></span>

<?php echo $row_rsLandscapes['desc']; ?></td>
</tr>

I have another image called "not_avail.jpg" that i need to display if the intended image is not there.

Please help!!

davidj
04-12-2006, 08:30 AM
<tr align="left" valign="top">
<td width="250" rowspan="2">




<?php if($row_rsLandscapes['thumbs'] !=''){ ?>

/picgallery/<?php echo $row_rsLandscapes['thumbs']; ?>

<?php } else {?>


/picgallery/not_avail.jpg

<?php } ?>


</p>



Full Size</p>
</td>

<td width="210" class="main_text">
<span class="large_bold">
<?php echo $row_rsLandscapes['title']; ?>
</span>


<?php echo $row_rsLandscapes['desc']; ?>
</td>
</tr>

kona72
04-12-2006, 02:50 PM
PERFECT!!

One more quick question though...
Right now it checks for an empty field right? What if the image name and image descritpion are spelled two different ways? I need the image to show then as well...

Any ideas???

davidj
04-12-2006, 03:56 PM
if your image name in the database is spelled differently from the file then this is going to cause problems

how would the application know that a spelling error has occured

image1.jpg == imge1.jpg

how would the application know that the above example is a typo and not another image ?

kona72
04-12-2006, 04:38 PM
DB Structure is as follows
primary_key
title
category
thumbs
full_size
desc
paypal

I have the client updating the DB using the insert record server behaviour. Images are uploaded to the /picgallery folder using a php upload script. So by doing this he has to type in the EXACT name of the image he has uploaded with php script into the 'thumbs' and 'fullsize' category.

ie: if the image name is 'example_thumb.jpg' he would use the script to upload the image and then go to the insert form and in the thumbnail field he would have to ensure that he types in example_thumb.jpg exactly as it is named.

I hope I have made sense of all this..