Re: [PHP] Getting mysql_query results into an array
- From: ceo@xxxxxxxxx ("Richard Lynch")
- Date: Wed, 14 Feb 2007 18:51:44 -0600 (CST)
On Wed, February 14, 2007 11:34 am, Bill Guion wrote:
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.
The original question was "what's most efficient".
For a small number of items (like 15) the efficiency probably isn't
all that big a deal...
For a large number, however, you still might be better off with a
"select count(*)" query, and then use some sort of modulus operator
with a row number in the DB to order the data. Or maybe not, as you
won't have an index on that, most likely... All depends on your
hardware, your data, your situation...
All that said, outputting them as div/span tags might actually be most
efficient, and play a trick with CSS to get them aligned the way you
want, even though they appear in the original order within the raw
HTML output.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
.
- References:
- Re: [PHP] Getting mysql_query results into an array
- From: "Richard Lynch"
- Re: [PHP] Getting mysql_query results into an array
- From: Bill Guion
- Re: [PHP] Getting mysql_query results into an array
- Prev by Date: Re: [PHP] Object ID
- Next by Date: Re: PDFLib Broke on Windows PHP Binaries -- need new binary
- Previous by thread: Re: [PHP] Getting mysql_query results into an array
- Next by thread: Email authentication
- Index(es):
Relevant Pages
|