Got a suggestion to use the following code, it does pull all categories from DB but it puts them in a single long row. I need 3 columns of 8 if possible.
Any ideas please?
<?php
include 'includes/dbconnect.php';
$result = mysql_query("SELECT category FROM CATEGORIES");
echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\"><tr>";
$i = 0;
while($array = mysql_fetch_array($result)){//loop through
$i++;
echo "<td>". $array['category']. "</td>";
if(!$i%3){echo "</tr><tr>";$i=0;}
}
$num_rows = mysql_num_rows($result);
$find_colspan = 3 - ($num_rows%3);//if there are 6 rows, this is 0, if there are 7, this is 1.
for($i=0;$i<$find_colspan;$i++){
echo "</td>";
}
echo "</tr></table>";
?>
View Source code:
<table border="1" cellpadding="2" cellspacing="2"><tr><td>Accommodations - Hotels & Resorts</td><td>Arts & Entertainment</td><td>Automotive</td><td>Business & Professional Services</td><td>Clothing & Accessories</td><td>Community & Government</td><td>Computers & Electronics</td><td>Construction & Contractors</td><td>Education</td><td>Food & Dining</td><td>Government, Community, Schools, Churches</td><td>Health & Medicine</td><td>Home & Garden</td><td>Industry & Agriculture</td><td>Internet</td><td>Legal & Financial</td><td>Media & Communications</td><td>Personal Care & Services</td><td>Real Estate</td><td>Shopping</td><td>Sports & Recreation</td><td>Travel & Transportation</td><td>Wedding Services</td><td>Non-Profits</td></td></td></td></tr></table>