Okay, I've fiddled with this for two days now and can't seem to get the code to work how I want it to. It does work and gets the display that I want, but when a row has a remainder, they do not follow suite.
My code does three things: 1) Creates a new table when the first letter in the last name changes, 2) separates the table into three columns and 3) alternates the row colors.
My Code:
<?
$rownum = 1;
$displaycols = 3;
$column = 0;
while ($row = mysql_fetch_array ($result))
{
$currentletter = substr($row['lname'], 0, 1);
$rowcolor = (($rownum % 2) == 0) ? "evenrow" : "oddrow";
if ($lastletter <> $currentletter) {
$column = 0;
echo("<table class=\"tablehead\" cellpadding=\"3\" cellspacing=\"1\">");
echo("<tr class=\"stathead\" style=\"background:#000066\"><td colspan=\"3\"><a name=\"{$currentletter}\">{$currentletter}</a></td></tr>");
}
if ($column == 0) {
echo("<tr class=\"$rowcolor\" valign=\"top\">");
}
echo("<td width=\"33%\"><div><a href=\"player.php?playerid={$row['playerid']}\">{$row['lname']}, {$row['fname']}</a></div></td>");
$column++;
if ($column == $displaycols) {
echo("</tr>");
$column=0;
$rownum++;
}
$lastletter = substr($row['lname'], 0, 1);
}
echo "</table>";
?>
My Screenshot:
