I have a members directory that echoes name, address, phones, etc. I want to indicate which phone numbers are home, cell or work, but I don't want the html of home, work or cell to appear if the entry does not have one or more of those phone numbers. Is there a way to suppress this information and have the field name only appear if there is information in that field? Here is the code with the three phone names in it.
echo "<ul>\n";
echo "<li>" . $First_Name . " " . $Last_Name . "</li>\n";
echo "<li>" . $Home_Phone . " Home</li>\n";
echo "<li>" . $Cell_Phone . " Cell</li>\n";
echo "<li>" . $Work_Phone . " Work</li>\n";
echo "<li>" . "<a href=mailto:" . $Email . ">" . $Email . "</a></li>\n";
echo "<li>" . $Home_Street . "</li>\n";
echo "<li>" . $Home_City . ", " . $Home_State . " " . $Home_Zip . "</li>\n";
echo "<li>" . $Troop_Role . "</li>\n";
echo "<li>" . $Patrol . "</li>\n";
echo "</ul>";
Use a ternary operator for a quick check
echo "<ul>\n";
echo (empty($Home_Phone)) ? '' : "<li>" . $Home_Phone . " Home</li>\n";