Posted on: 08/27/05 12:33pm
By: jdustin
$maxcols = 4; $colpercent = round(100 / $maxcols); $rst = mysql_query("select count(lid) from gl_links"); $rec = mysql_fetch_array($rst, MYSQL_ASSOC); $qcnt = $rec["count(lid)"]; mysql_free_result($rst); $rst = mysql_query("select count(distinct category) from gl_links"); $rec = mysql_fetch_array($rst, MYSQL_ASSOC); $ccnt = $rec["count(distinct category)"]; mysql_free_result($rst); //Make the nominal column count evenly divisible by maxcols if (($qcnt+$ccnt) % $maxcols > 0) { $qcnt+=$maxcols-(($qcnt+$ccnt) % $maxcols); } $rst = mysql_query("select * from gl_links order by category, title"); echo ""; $i=round(($qcnt+$ccnt)/$maxcols)-1; $colcount=0; $lastcat=""; while ($rec = mysql_fetch_array($rst, MYSQL_ASSOC)) { $cat = $rec['category']; if($cat!=$lastcat) { if($colcount if($i>=round(($qcnt+$ccnt)/$maxcols)-1) { echo ""; $i=0; $colcount+=1; } } echo "<b>$cat</b><br>"; $i+=1; $lastcat = $cat; } if($colcount if($i>=round(($qcnt+$ccnt)/$maxcols)) { echo ""; $i=0; $colcount+=1; } } $lid = $rec['lid']; $title = $rec['title']; $url = $rec['url']; echo "<a href="$url">$title</a><br>"; $i+=1; } mysql_free_result($rst); echo "";