Er, actually -- I just reviewed this...
It wraps across, not down. That's why I posted the original code, in my first note -- because I already have an 'across' wrapper. My client insists it wrap down.
I actually found the original code in another forum just now; there was a missing definition that, once implemented, allows this code to work. I don't know if I'm permitted to post this, but am doing it anyway, because it's very helpful (column by Matt Wade), and took me 3 days to find; I'd like it here for others to share since my subject title should make searching much easier. 😃
<?PHP
$columns = 4;
mysql_connect('localhost','','');
mysql_select_db('test');
$query = "SELECT stuff FROM mystuff ORDER BY stuff";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
//we are going to set a new variables called $rows
$rows = ceil($num_rows / $columns);
//to do this display, we will need to run another loop
//this loop will populate an array with all our values
while($row = mysql_fetch_array($result)) {
$data[] = $row['stuff'];
}
echo "<TABLE BORDER=\"0\">\n";
//here we changed the condition to $i < $rows
for($i = 0; $i < $rows; $i++) {
echo "<TR>\n";
//here will run another loop for the amount of columns
for($j = 0; $j < $columns; $j++) {
if(isset($data[$i + ($j * $rows)])) {
echo "<TD>" . $data[$i + ($j * $rows)] . "</TD>\n";
}
}
echo "</TR>\n";
}
echo "</TABLE>\n";
?>
also included was one for multiple column display:
<?PHP
$columns = 4;
mysql_connect('localhost','root','LRMSys2k');
mysql_select_db('test');
//change the query to get another field from the database
$query = "SELECT stuff, morestuff FROM mystuff ORDER BY stuff";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
$rows = ceil($num_rows / $columns);
while($row = mysql_fetch_array($result)) {
$data[] = $row['stuff'];
//store the other field into an array
$data2[] = $row['morestuff'];
}
echo "<TABLE BORDER=\"0\">\n";
for($i = 0; $i < $rows; $i++) {
echo "<TR>\n";
for($j = 0; $j < $columns; $j++) {
if(isset($data[$i + ($j * $rows)])) {
echo "<TD>" . $data[$i + ($j * $rows)] . "</TD>\n";
//echo out the field
echo "<TD>" . $data2[$i + ($j * $rows)] . "</TD>\n";
}
}
echo "</TR>\n";
}
echo "</TABLE>\n";
?>
I would have posted the URL in the other forum, but am not sure of the rules here. (which I should have read, but now I'm here in edit mode....)
Strat