oraya Posted January 23, 2008 Share Posted January 23, 2008 On one of the pages on the site I'm pulling names and addresses. So there are as follows Name ad_one ad_two ad_three town county post_code The problem is that not everyone has three lines for there address, so when I place each line on the page I might get a gap between the second line of the address and the town: <?php echo stripslashes($name); ?><br> <?php echo stripslashes($ad_first); ?><br> <?php echo stripslashes($ad_second); ?><br> <?php echo stripslashes($ad_third); ?><br> <?php echo stripslashes($town); ?><br> <?php echo $county; ?><br> <?php echo $post_code; ?> Could some one tell me how I may write and if and else statement so those fields that don't have any data in don't get shown. I did something similar on another page, but it was for just the one result pulled from the database like so: $result=mysql_query($query); $num=mysql_numrows($result); if (mysql_num_rows($result)>0){ echo "<p>There are no Frequently Asked Questions in the database at present. Would you like to add some?</p>"; } else { } but I can't figure out how to do it when pulling several different results. Sorry if this has been asked before, i did do a quick search. Being new to php (6months) I struggle with some things that may seem obvious to others. Many many thanks in advance to anyone that is able to point me in the right direction. Oraya Quote Link to comment https://forums.phpfreaks.com/topic/87308-solved-not-displaying-empty-results/ Share on other sites More sharing options...
forumnz Posted January 23, 2008 Share Posted January 23, 2008 Well, using the above code you are going to get something like: NameAddress1Address2Address3 etc, so you need a few breaks. if ($add_one != "") { echo $add_one . "<br>"; } and so on... Not tested, Sam. PS you dont need an else statement. Quote Link to comment https://forums.phpfreaks.com/topic/87308-solved-not-displaying-empty-results/#findComment-446566 Share on other sites More sharing options...
oraya Posted January 23, 2008 Author Share Posted January 23, 2008 Thank you so much sam, just about to go and try it out. I'm very greatful! Oraya Quote Link to comment https://forums.phpfreaks.com/topic/87308-solved-not-displaying-empty-results/#findComment-446567 Share on other sites More sharing options...
oraya Posted January 23, 2008 Author Share Posted January 23, 2008 Thank you sooooo much! That works like a charm, I've spent hours trying to figure out how to do it. You guys make it look so easy. Maybe in a few years (lol) it will seem easy to me. But teaching myself is turning into a real labour of love. Thank you once again, have a great week. Oraya Quote Link to comment https://forums.phpfreaks.com/topic/87308-solved-not-displaying-empty-results/#findComment-446568 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.