Jump to content

[SOLVED] Not displaying empty results


oraya

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.