I have a single table that has multiple entries...such as Name, Home Phone, Work Phone and Cell Phone. As you can see from the code below, when I query someones name it shows their information...even if there is none to show:
Joe Smith
Home Phone: 888-6887
Work Phone:
Cell Phone: 888-6884
What I would like to be able to do is have the code hide information that is not in the database. For example, Joe Smith doesn't have a work phone number so I would like the query results to look like:
Joe Smith
Home Phone: 888-6887
Cell Phone: 888-6884
So the script automatically didn't show 'Work Phone' since there is no entry there in the database.
Here is my code from my results page:
<?
mysql_connect("localhost","name","password");
mysql_select_db("database");
$search=$_POST["search"];
if(!$search)
{
echo("Please Input Something To Search For");
}
else
{
$result = mysql_query("SELECT * FROM table WHERE name LIKE '%$search%' ORDER BY name");
//grab all the content
while($r=mysql_fetch_array($result))
{
$name=$r["name"];
$home=$r["home"];
$work=$r["work"];
$cell=$r["cell"];
echo "<strong>$name</strong><br> <i>Home Phone:</i> $home<br> <i>Work Phone</i>: $work<br> <i>Cell Phone</i>: $cell<br><br>";
}
}
?>
Appreciate any info!
Thanks.