This is the logic I would use count number of results table rows = num results / 5 (maybe floor() or ceil() it) read results into a 2D array fill column 1 first when column 1 fills up, reset row count to 0 and inc. col count whizz through your array and display the table as needed
HTH Martin -----Original Message----- From: Jason Soza [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 11, 2002 4:05 PM To: PHP-General Mailing List Subject: [PHP] Table Making I'm driving myself crazy trying to visualize what I want to do, so I thought I'd share the insanity and hope for some advice. I have this nice piece of code to take my SQL result and organize it into a nice 5 column table: print "<center><table width=\"100%\" border=\"0\">\n"; //start table $i=0; //define variable - avoid errors $grad_year=""; //define variable - avoid errors while ($row = mysql_fetch_array($sql)) { extract($row); $i++; if($i=="1") { print "<tr>\n"; //start table row on $i = 1 } printf("<td align=\"center\"><a href=\"year.asp?year=%s\">%s</a><br></td>\n", $grad_year, $grad_year); //print links if ($i=="5") { print "</tr>\n"; //end table row on $i = 5 to get 5 columns $i=0; //reset $i } $grad_year=""; //clear $grad_year } if ($i<5) print "</tr>\n"; //end any rows with less than 5 columns print "</table></center><p>\n"; //end table -------------------END------------------------ Now, this works great for most things - it takes my SQL results and puts them in a table sequentially, from left to right, top to bottom. So in this case, the top-left cell displays "1941", the top-right cell displays "1945", the next row starts with "1946" on the left and goes to "1950" on the right, and so on. What I want is rather than sorting left to right, top to bottom, I want to sort top to bottom, left to right. So the top-left would still be "1941", but rather than increasing to the right, it would increase down, then continue at the top of the next column. I'm thinking this might be an easy thing to do with some creative use of $i and print, but I just can't think it out. I'm guessing $i would be used to limit the amount of items in a column... But, I'm in need of some guidance to get it right. I can't even begin to think where to start. Any help would be great - thanks! Jason Soza -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php