Jump to content

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


erme

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");

 

 

Archived

This topic is now archived and is closed to further replies.

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