View Single Post
Old 01-29-2010, 08:26 PM  
JD
Too lazy to set a custom title
 
Industry Role:
Join Date: Sep 2003
Posts: 22,651
Quote:
Originally Posted by borked View Post
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 ;)
it's coming from WP so there's not quite as much room code wise
JD is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote