hemangi Posted April 18, 2009 Share Posted April 18, 2009 HI everyone, I am beginner in PHP and I need help with little code. I am making a web site in Dreamweaver using MySql database and PHP. I have image address in row 10 of the database table and I display them well but they only exist for some of the records, not all. But when I place the recordset on the page and test it in browser-it displays the image when the recordset contains it's address, but it displayes an empty image (like broken link one) for all the rest of the records. What I need is simple if else statement in php to tell it to display alternative image or nothing when the row record is empty. I have this code, but is obviously wrong because it gives me an error: <?php if ($row_rsList['WL']==""){ echo "images/emptyGraphic.gif"}?> <?php else echo $row_rsList['WL'] /> "rsList" is my recordset in dreamweaver which contains all the table rows and "WL" is row number 10. I place instances of all the row in the page, like phone:... email:... etc and I also would like to know how to make them not show if the record is empty. Instead I have now empty line where this record was supposed to be. I would like it to ignore the line and bring the next record directly under it. Can you please help me !!! Regards, Emiliya Link to comment https://forums.phpfreaks.com/topic/154597-solved-how-to-display-alternative-image-if-database-record-is-empty/ Share on other sites More sharing options...
Coreye Posted April 18, 2009 Share Posted April 18, 2009 You could do this: <?php if(!$row_rsList['WL']) { echo "images/emptyGraphic.gif" } else { echo $row_rsList['WL']; } ?> Link to comment https://forums.phpfreaks.com/topic/154597-solved-how-to-display-alternative-image-if-database-record-is-empty/#findComment-813134 Share on other sites More sharing options...
JD* Posted April 18, 2009 Share Posted April 18, 2009 Or a slimmer way: <?php echo (!$row_rsList['WL'] ? "images/emptyGraphic.gif" : $row_rsLiost['WL']); ?> This does a comparison of two cases. Link to comment https://forums.phpfreaks.com/topic/154597-solved-how-to-display-alternative-image-if-database-record-is-empty/#findComment-813343 Share on other sites More sharing options...
keeB Posted April 18, 2009 Share Posted April 18, 2009 Slimmer != better. This guy is writing in dreamweaver. That tells you he's not ready for short hand if statements. Link to comment https://forums.phpfreaks.com/topic/154597-solved-how-to-display-alternative-image-if-database-record-is-empty/#findComment-813344 Share on other sites More sharing options...
hemangi Posted April 19, 2009 Author Share Posted April 19, 2009 Thanks very much guys, it all works fine now! I like it slim and I am a girl Link to comment https://forums.phpfreaks.com/topic/154597-solved-how-to-display-alternative-image-if-database-record-is-empty/#findComment-813602 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.