Forum Moderators: coopster

Message Too Old, No Replies

Hiding blank fields?

         

dorfmunder

7:02 pm on Feb 3, 2009 (gmt 0)

10+ Year Member



Hi, I am wondering if there's a way to prevent blank fields from showing up on a query?

I want my format to be:

Name
Address
City, State ZIP
Phone
Email
Website

But if any of those fields are blank, I want them to bump up so there isn't a blank line. Is this possible? Was thinking somehow there could be an "if not null" query on each line or something?

Here's my code (although highly doubtful anyone needs it, very simple LOL):


<?php
$result = mysql_query("SELECT * FROM data WHERE name LIKE '%blah'")
or die(mysql_error());

while($row = mysql_fetch_array( $result )) {
echo "<span class='style4'>";
echo $row['name'];
echo "</span><br>";
echo $row['address1']. " <br> "
.$row['city']. ", " .$row['state']. "&nbsp;" .$row['zip']. " <br> "
.$row['email']. " <br> "
.$row['phone'].

"<br /><br>";
}
?>

Thanks a million!
Melanie

dreamcatcher

7:09 pm on Feb 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Melanie,

A couple of ways you can do this. How about a simple check in your while loop using an if statement?

Example:

if ($row['name']) {
echo $row['name'];
}

dc