Two Column MYSQL display + Alph Grouping
Posted: Sun Mar 25, 2007 6:19 am
Hi everyone, I'm still a beginner at PHP, so bear with me
I have this code that I compiled from several tutorials:
The output looks like this:
feyd | 65K image changed to link.
http://img124.imageshack.us/img124/3239/ssax6.jpg
So, I was wondering why it doesn't two-column it correctly and how I fix it?
I have this code that I compiled from several tutorials:
Code: Select all
$columns = '2';
$letterlinks = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
echo '<a name="#top"></a>';
echo '<a href="#number">0-9</a> ';
for ($i = 0; $i < 26; $i++)
{
echo '<a href="#'.$letterlinks[$i].'">'.$letterlinks[$i].'</a> ';
}
$num_rows = mysql_num_rows($result);
echo "<table border=\"0\" cellspacing\"0\" cellpadding=\"0\" width=\"100%\">\n";
for($i = 0; $i < $num_rows; $i++)
{
$list = $db->sql_fetchrow($result);
$letter = strtoupper(substr($list['name'], 0, 1));
if (@$prev_row != '0-9' && is_numeric($letter))
{
echo "<tr>\n";
echo "<td colspan=\"2\" align=\"center\">\n";
echo '<hr><br /><a name="#number"></a><b><u>0-9</u></b> ';
echo '<a href="#top"><i>goto top</i></a><br /><hr><br /><br />';
echo "<td>\n";
echo "</tr>\n";
$prev_row = '0-9';
}
if ($letter != @$prev_row && !is_numeric($letter))
{
echo "<tr>\n";
echo "<td colspan=\"2\" align=\"center\"><hr>\n";
echo '<a name=#"'.$letter.'"></a><b><u>'.$letter.'</u></b> ';
echo '<a href="#top"><i>goto top</i></a><br /><hr><br /><br />';
echo "</td>\n";
echo "</tr>\n";
$prev_row = $letter;
}
if($i % $columns == 0)
{
//if there is no remainder, we want to start a new row
echo "<tr>\n";
}
echo "<td>" . $list['name'] . "</td>\n";
if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows)
{
//if there is a remainder of 1, end the row
//or if there is nothing left in our result set, end the row
echo "</tr>\n";
}
}
echo "</table>\n";The output looks like this:
feyd | 65K image changed to link.
http://img124.imageshack.us/img124/3239/ssax6.jpg
So, I was wondering why it doesn't two-column it correctly and how I fix it?