Jump to content

Display something only if something is in that field in the db


Recommended Posts

Currently I have this:

 

while($r = mysql_fetch_array($inter))

  {

echo "<div class=\"". ($r['Package']) ."\">";

echo "<h2>" . $r['BusinessName'] . "</h2>";

echo "<address>THE ADDRESS IS:" . $r['Address'] . "</address>";

echo "</div> \n";

  }

 

But I only want Address to be displayed if there is something in Address. Otherwise I will always have THE ADDRESS IS: and then nothing.

 

Many thanks guys.

After connecting to your db you can use "mysql_num_rows" which looks a little something like this:

 

$inter = mysql_query("here you put whatever your query is");
  $record_count = mysql_num_rows($inter);

if ($record_count >= 1)
{

while($r = mysql_fetch_array($inter))
  {
   echo "<div class=\"". ($r['Package']) ."\">";
      echo "<h2>" . $r['BusinessName'] . "</h2>";
      echo "<address>THE ADDRESS IS:" . $r['Address'] . "</address>";
   echo "</div> \n";
  }

}
else
die("You do not have an address");

 

 

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.