Is there a way to modify this script so that if a value returned is null that it won't print that particular field? Basically, this script grabs each user, address, and phone numbers in my family. If someone doesn't have a work number listed, or cel-phone listed, I would prefer it not add anything (like a "Work:" or "Cell:" field) for that user.
For example:
First Name Last Name
555 Some drive
Some City, CA 12345
Home: 555-555-5555
Work:
Cell: 444-444-4444
Would look like:
First Name Last Name
555 Some drive
Some City, CA 12345
Home: 555-555-5555
Cell: 444-444-4444
But would not affect other users like:
First Name Last Name
444 Some Other drive
Some Other City, WY 98765
Home: 555-555-5555
Work: 333-333-3333
Cell: 444-444-4444
Thanks in advance:
PHP Code:
<?php
include 'config2.php';
include 'opendb.php';
// here's a quickie function to print the address from
// an associative array. We'll use it in a moment
function printaddr($addr){
echo "<b>{$addr['NameF']} {$addr['NameL']}</b><br />\n";
echo "<b>" . nl2br($addr['Address']) . "</b><br />\n";
echo "Home: {$addr['Home']}<br />\n";
echo "Work: {$addr['Work']}<br />\n";
echo "Cell: {$addr['Cell']}<br />\n<br />\n";
}
// get the data from DB
$query = "SELECT NameF, NameL, Address, Home, Work, Cell FROM Contacts WHERE Affiliation = 'family' ORDER BY NameL";
$result = mysql_query($query);
// now put everything in one big array
$BigAddressArray = array();
while($row = mysql_fetch_array($result)){
$BigAddressArray[] = $row;
}
// chunk the array for three column output
// note that if you wanted 2 or 4 or 12 column
// output you only need to change the last
// argument in array_chunk(). Everything else
// stays the same.
$AddressTable = array_chunk($BigAddressArray, 3);
echo "<table>\n";
foreach($AddressTable as $TableRow){
echo "<tr>";
foreach($TableRow as $TableCell){
echo '<td valign="top" width="250px">';
printaddr($TableCell);
echo '</td>';
}
echo "</tr>\n";
}
echo "</table>\n";
include 'closedb.php';
?>
<form><center>
<input type="button" value="Print This Page" onClick="window.print()" /></center>
</form>