This is one way of doing it: - calculate how many rows are needed given the total number of records (mysql_num_rows()) and how many columns you want. - loop through all records and store them in a two-dimensional array starting at arr[0][0] to arr[maxrows][0] and then increment the 'column' and store arr[0][1] to arr[maxrows][1] etc. - loop through the array the other way round and create the html-table. So start with arr[0][0] to arr[0][4] etc.
Make any sense? Another way of doing it is to use mysql_data_seek() to jump back and forth in the result set. Regards Joakim Andersson > -----Original Message----- > From: Jason Soza [mailto:[EMAIL PROTECTED]] > Sent: Thursday, July 11, 2002 8:05 AM > 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