Re: [PHP] Getting mysql_query results into an array



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.

it not beyond the possible to output 3 blocks in series and use CSS to
visually style the information according to the N-column layout you desire.

given that what you describe is pure layout I don't think it hold up in theory,
in practice your are often going to want to use a table to avoid a bunch of headaches

.... then again a fancy bit of javascript could be used to rewrite the dom
on the client side (i.e. build an N-column table/layout using blocks/elements of information
that has been output serially ... then again that raises the issue of usability
with regard to using javascript.


... just a thought.


-----===== Bill =====-----
.



Relevant Pages

  • Re: .join() !== + a + b; // for some a and b
    ... This is a situation that is probably all too common in many, if not most, programming languages, where slips in the construction of an expression result in an alternative expression, rather than a syntax error. ... There are languages where assignment would not be allowed in that context, but in javascript assignment is an expression and all expressions are allowed to drive - if - statements. ... The consequence of missing the comma out is that two expressions that would each define one element in an array become a single expression, ... The use of the comma operator in the expression in the property accessor's brackets may make the outcome more obscure but it still does not prevent the whole expression from being valid. ...
    (comp.lang.javascript)
  • Re: to ajax or not
    ... each customer is called with 1 query and then added to a javascript ... them in with data from the address array. ... even if the validation comes after the ajax call. ... This means a query for each ...
    (comp.lang.javascript)
  • Re: help with arrays
    ... You're too kind, Trevor. ... A JavaScript object is basically ... is using an array of images, combined with an array of URLs, to build ... This is the code that is behind the arrow ...
    (microsoft.public.frontpage.programming)
  • Re: Array in javascript
    ... The only danger is of wasting ones time as your intellectual ... exhibiting 'jaggedness' created with a single javascript Array instance ... IF THEN (NOT a single Array object) ... When you announced last week that one month of studying Mozilla ...
    (comp.lang.javascript)
  • Re: Very Strange problem with my AJAX code
    ... The php routine that is called interrogates the database, cereates an array and then uses that array to build the message that is sent back to the receiving javascript code. ... you don't show what's in $charges; your problem could very well be before this. ...
    (comp.lang.php)