erme Posted January 6, 2010 Share Posted January 6, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/187397-display-something-only-if-something-is-in-that-field-in-the-db/ Share on other sites More sharing options...
squiblo Posted January 6, 2010 Share Posted January 6, 2010 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"); Quote Link to comment https://forums.phpfreaks.com/topic/187397-display-something-only-if-something-is-in-that-field-in-the-db/#findComment-989601 Share on other sites More sharing options...
trq Posted January 6, 2010 Share Posted January 6, 2010 if ($r['Address']) { echo "<address>THE ADDRESS IS:" . $r['Address'] . "</address>"; } Quote Link to comment https://forums.phpfreaks.com/topic/187397-display-something-only-if-something-is-in-that-field-in-the-db/#findComment-989602 Share on other sites More sharing options...
erme Posted January 6, 2010 Author Share Posted January 6, 2010 Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/187397-display-something-only-if-something-is-in-that-field-in-the-db/#findComment-989624 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.