scaleautostyle Posted April 29, 2011 Share Posted April 29, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235102-how-can-i-write-this-if-sentence/ Share on other sites More sharing options...
fugix Posted April 29, 2011 Share Posted April 29, 2011 $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 Quote Link to comment https://forums.phpfreaks.com/topic/235102-how-can-i-write-this-if-sentence/#findComment-1208236 Share on other sites More sharing options...
scaleautostyle Posted April 29, 2011 Author Share Posted April 29, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235102-how-can-i-write-this-if-sentence/#findComment-1208239 Share on other sites More sharing options...
Pikachu2000 Posted April 29, 2011 Share Posted April 29, 2011 Run your query as you normally would, then when looping the results if the image field is empty, echo the filename/path of the default image. Quote Link to comment https://forums.phpfreaks.com/topic/235102-how-can-i-write-this-if-sentence/#findComment-1208240 Share on other sites More sharing options...
wildteen88 Posted April 29, 2011 Share Posted April 29, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235102-how-can-i-write-this-if-sentence/#findComment-1208241 Share on other sites More sharing options...
Pikachu2000 Posted April 29, 2011 Share Posted April 29, 2011 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']; Quote Link to comment https://forums.phpfreaks.com/topic/235102-how-can-i-write-this-if-sentence/#findComment-1208242 Share on other sites More sharing options...
scaleautostyle Posted April 29, 2011 Author Share Posted April 29, 2011 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'/>"; Quote Link to comment https://forums.phpfreaks.com/topic/235102-how-can-i-write-this-if-sentence/#findComment-1208262 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.