View Single Post
Old 01-29-2010, 03:26 PM  
borked
Totally Borked
 
borked's Avatar
 
Industry Role:
Join Date: Feb 2005
Posts: 6,284
why can't you do it in a table? Why does it have to be an <UL>?

From a mysql query, let's say you retrieve 20 results (for nice round numbers for this eg) and you want 4 columns.

Then you know there will be 5 rows.

Code:
for ($i=0; $i<$numRows; $i++) {

  echo "<tr>";

  for ($k=0; $k<$numCols; $k++) {
    $key = ($k * $numRows) + $i;
    echo "<td>".$content[$key]."</td>
  }
  
  echo "</tr>";
}

The code above will fit your 2x3, 3x4, 3x3, 4x5 anything stuff. It just won't handle things having eg 21 results - you need standard code to add cell padding for that.

Kind of like taking a horse to water, but you can't make it drink ;)
__________________

For coding work - hit me up on andy // borkedcoder // com
(consider figuring out the email as test #1)



All models are wrong, but some are useful. George E.P. Box. p202

Last edited by borked; 01-29-2010 at 03:30 PM..
borked is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote