Greetings...
I have some code that I am trying to apply to a different area of my site... the issue is that the data used for this page is not an even number and gets stuck in a loop (there were say 40 rows in the one that worked and only 39 here). If I enter a bogus row to make the number of rows even it works - except this doens't really help.
So what I need is a way to handle remainders...
<?php
$result = mysql_query ("SELECT beerstyle_id, beerstyle_name FROM bm_beerstyle ORDER BY beerstyle_name") or die(mysql_error());
$total = mysql_num_rows($result);
$numCols = 2;
$numRows = floor($total / $numCols);
while($row = mysql_fetch_array($result))
{
$beerstyle_id = $row['beerstyle_id'];
$beerstyle_name = $row['beerstyle_name'];
echo ('<table width="80%">');
for ($y = 0; $y < $numRows; $y++) {
echo ('<tr>');
for ($x = 0; $x < 2; $x++) {
$offset = $y + ($x * $numRows);
if ($offset < $total) {
mysql_data_seek($result, $offset);
$row2 = mysql_fetch_array($result);
echo ('<td width="50%"><a href="beerstyle.php?id='.$row2['beerstyle_id'].'">'.$row2['beerstyle_name'].'</a></td>');
}
}
echo ('</tr>');
}
echo ('</table>');
}
?>