http://www.pstvalumni.com/directory/
And here's my code that I adjusted from tutorial examples:
- Code: Select all
<html>
<body>
<?php
$db = mysql_connect("localhost", "pstvalu_director", "XXXXXXX");
mysql_select_db("pstvalu_directory",$db);
$result = mysql_query("SELECT * FROM alumni ORDER BY lastname",$db);
if ($myrow = mysql_fetch_array($result))
{
echo "<table border=1>\n";
echo "<tr>
<td>Name</td>
<td>Class</td>
<td>Location</td>
</tr>\n";
do {
printf("<tr>
<td>%s (%s), %s</td>
<td>%s</td>
<td>%s, %s</td>
</tr>\n",
$myrow[lastname],
$myrow[maidenname],
$myrow[firstname],
$myrow[classyear],
$myrow[city],
$myrow[state]);
}
while ($myrow = mysql_fetch_array($result));
echo "</table>\n";
}
else {
echo "Sorry, no records were found!";
}
?>
</body>
</html>
In general it works. I want to put people's maiden name in parenthesis following their last name, then followed by a comma, then their first name. This works perfectly for the first item. But the other 98% of the rows do not have maiden names in the mySQL database (they're blank). Is there a way I can alter this code so that it will only print the "(" and ")" on each side of the "%s" ONLY if there is data associated with that column?
The same situation effects those people who don't have cities and states associated with them, in which case they still get a comma in that section.
Please help! Thanks.


