If statement i think

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

If statement i think

Post by jamrop »

Hey i am trying to show a picture that is the name of a id key for a car. The thing i am trying to work out, is that is there is not a picture, how what i put a message saying 'awaiting picture'

code

Code: Select all

<?php
<?php $sql = 'SELECT * FROM cars ' ; 


						$rs=mysql_query($sql,$db);
							while ($r = mysql_fetch_array($rs))
								{
									$carid=$r["carid"];
									$make=$r["make"];
									$engine=$r["engine"];
									$year=$r["year"];
									$des=$r["des"];
									$mot=$r["mot"];
									$price=$r["engine"];
									  ?>
                            <tr> 
                              <td bgcolor="#99CCFF"> <strong><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"> 
                                <?php echo $make ?></strong></td>
                            </tr>
                            <tr> 
                              <td><img src = "uploaded/<?php echo $carid?>.jpg"></td>


?>

Many thanks
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Code: Select all

if(!file_exists("uploaded/".$carid.".jpg")){
  echo "awaiting picture";
}
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

hey thanks

i have been trying this so the x picture does not show, but it does not seem to be working

Code: Select all

<?php
 if(!file_exists("uploaded/".$carid.".jpg")){?>
<img src = "uploaded/<?php echo $carid; ?>.jpg">
<?php } else { 
  echo "awaiting picture"; 
} 
?>
any ideas?

many thanks
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Code: Select all

<?php
 if(!file_exists("uploaded/".$carid.".jpg")){
  echo "awaiting picture"; 
} else {
?>
<img src = "uploaded/<?php echo $carid; ?>.jpg">
<?  
} 
?>
The ! before the file_exist meens, not..
So the statement is 'if file not exists do say `awaiting picture` else show image'
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

ah i c

thanks
Post Reply