RE: [PHP] Getting mysql_query results into an array
| From: | Kristen G. Thorson | Date: | Wed, 14 Feb 2007 18:58:58 +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-248881@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Bill Guion [mailto:bguion@comcast.net]
> Sent: Wednesday, February 14, 2007 12:35 PM
> To: PHP-General
> Subject: Re: [PHP] Getting mysql_query results into an array
>
> At 6:22 PM -0600 2/13/07, Richard Lynch wrote:
>
> >
> >The most efficient way is "Don't do that." :-)
> >
> >Simply loop through the results and do whatever you want to do with
> >them, and don't put them into an array at all.
> >
> >This question has appeared before, and usually breaks down to one of
> >these scenarios:
> >
> >#1
>
> snip 1
>
> >
> >#2
>
> snip 2
>
> >
> >#2 does occasionally have an exception to the rule, where the SQL
> >query is nasty and the PHP is fast and easy, but that's awfully rare.
> >
> >
>
> 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