RE: [PHP] Getting mysql_query results into an array

From: Date: Wed, 14 Feb 2007 19:32:20 +0000
Subject: RE: [PHP] Getting mysql_query results into an array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-248885@lists.php.net to get a copy of this message
> > How about scenario #3: I wish to output my data in (for example) > > three columns, as a phone book does. To make the example simple, > > assume 15 data points. I wish the output to look like > > > > 1 6 11 > > 2 7 12 > > 3 8 13 > > 4 9 14 > > 5 10 15 > > > > So when I'm outputting row 1, I need data points 1, 6, and 11. Isn't > > it easier to generate the query, put in array, and output the rows > > from the array? Keep in mind, the number of data points might be > > variable, the constraints being n columns with approximately the same > > number of data point in each column. > > > > Instead of creating a whole array, why not just move the pointer of the > result set? Like so (the example prints rows in reverse order): > > http://us3.php.net/manual/en/function.mysql-data-seek.php Another solution to the example above would be something like this: <table> <tr> <td> <table> <? $i=0; for($j=1;$j<=15;$j++){ ?><tr><td><?= $j ?></td></tr><? $i++; if($i==5){ ?></table></td><td><table><? $i=0; } } ?> </table> </td> </tr> </table> The result is a table with 3 cells, each cell containing a table with 5 rows. The iterator closes the table and cell, and starts a new one every 5 records. A bit of tweaking and some additional logic could make it dynamic. :B

« previous php.general (#248885) next »