Jump to content

how can I write this if sentence


scaleautostyle

Recommended Posts

like I said I'm not very good in coding. so your help to solve this one is more than appreciate. this is what I want to do....

 

 

IF I have an image_id1 in the database please show it. other than that please show me the TBC.jpg picture.

 

in php/sql how this will be write.

 

thanks

 

sebastien

Link to comment
https://forums.phpfreaks.com/topic/235102-how-can-i-write-this-if-sentence/
Share on other sites

$query = mysql_query("select * from table_name where image_id1 !=''");
while ($row = mysql_fetch_assoc($query))  {

   $image = $row['image_id1'];
}

 

that will grab all of the rows where the image_id1 column is not blank..as to the other part of you question please explain further

thank you... this is what I have right now ( it's part of the complete code )

 

 
<?php

while($row=mysql_fetch_array($result)){ 
                           $image_id=$row['image_id1'];
                           $image_id=$row['image_id2'];


echo "  <table align=center width=\"1340\" border=\"\">\n";	
echo"  <td nowrap width='75'> <a href= ".$image_id1.">   <img src= '".$image_id1."' width='50' height='50' border='0'/>";
echo"  <td nowrap width='75'> <a href=".$image_id2.">   <img src='".$image_id2."' width='50' height='50' border='0'/>";

}   
   }  
   else{   
   echo  "<p>Please enter a search query</p>";   
   }   
   
?>  

 

this will show me what I have in my database. if nothing is theyre I ave a broken image. instead of the broken image I want a picture name TBC.jpg

 

I hope it's more clear like this.

 

thanks in advance

 

sebastien

Change this

echo"  <td nowrap width='75'> <a href= ".$image_id1.">   <img src= '".$image_id1."' width='50' height='50' border='0'/>";

to

if(!empty($image_id1))
    echo"  <td nowrap width='75'> <a href= ".$image_id1.">   <img src= '".$image_id1."' width='50' height='50' border='0'/>";
else
    echo "  <td width='75'></td>";

 

You'd do the same thing for the $image_id2 variable

You have a problem in these lines of code. You're overwriting the $image_id variable with the second image from the DB . . .

 

while($row=mysql_fetch_array($result)){ 
                           $image_id=$row['image_id1'];
                           $image_id=$row['image_id2'];

thnkas... with your help I found the way to do it ... here the final code... and it WORK PERFECTLY"

 

thanks again

 

if(!empty($image_id1))    echo"  <td nowrap width='75'> <a href= ".$image_id1."> <img src='http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50' border='0'/>";else    echo "  <td nowrap width='75'>    <img src='http://www.scale24-25.com/images/tbc.jpg' width='50' height='50' border='0'/>";

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.