
September 4th, 2008, 11:43 AM
|
|
Me
|
|
Join Date: Apr 2007
Location: San Diego, CA
Posts: 2,263
 
Time spent in forums: 2 Weeks 1 Day 5 h 48 m 56 sec
Reputation Power: 9
|
|
put the data into 4 arrays, one for each column and then compile it into your html code.
PHP Code:
<?php
//get the results from the db.
$r = mysql_query("SELECT `column` FROM `table` LIMIT 40");
//number of columns
$cols = 4;
//number of rows from result.
$count = mysql_num_rows($r);
//init some vars.
$i = 0;
$cols = array();
//loop through the results.
while($row = mysql_fetch_assoc($r)){
//get the column number. floor(loop count divided by ceil(maximum number of rows))
//should get us a number from 0 to 3.
$col = floor($i/ceil($count/$cols));
//add the row to a multi-dimensional array using the column number from above.
$cols[$col][] = $row['column'];
//add 1 to our loop count.
$i++;
}
//displaying
echo "<table>";
for($i=0;$i<count($cols[0]);$i++){
echo "<tr>";
foreach($cols as $k=>$v){
echo "<td id='R".($i+1)."C".($k+1)."'>{$v[$i]}</td>";
}
echo "</tr>";
}
echo "</table>";
?>
something like that should work. I haven't tested it, but it should be close enough to get it working.
|