Re: [PHP] is there a more efficient query?

2004-08-07 Thread Mattias Jönsson
;[EMAIL PROTECTED]> To: "Brian Tully" <[EMAIL PROTECTED]>, "Jay Blanchard" <[EMAIL PROTECTED]>, " PHP" <[EMAIL PROTECTED]> Subject: Re: [PHP] is there a more efficient query? Date: Fri, 6 Aug 2004 09:48:29 -0700 your only getting one row be

RE: [PHP] is there a more efficient query?

2004-08-06 Thread Jay Blanchard
[snip] but that only seems to return the first value. how should I be calling the results? ... do i need to do a while loop and create an array or something? [/snip] Yes, loop through the result set using either while or for. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit

Re: [PHP] is there a more efficient query?

2004-08-06 Thread Jason Davidson
your only getting one row beucase your only pulling one row from the array. You need to loop thru the rows to grab them all. Jason Brian Tully <[EMAIL PROTECTED]> wrote: > > on 8/6/04 12:28 PM, Jay Blanchard at [EMAIL PROTECTED] > wrote: > > > [snip] > > Tis SQL > > > > SELECT value >

RE: [PHP] is there a more efficient query?

2004-08-06 Thread Jason Davidson
I would use IN, or even BETWEEN if there exists such a function... Jay's example is much cleaner and readable. Jason "Jay Blanchard" <[EMAIL PROTECTED]> wrote: > > [snip] > Tis SQL > > SELECT value > FROM element_values > WHERE user = $user_id > AND(element=48 > OR element=52 > OR an

Re: [PHP] is there a more efficient query?

2004-08-06 Thread Brian Tully
on 8/6/04 12:28 PM, Jay Blanchard at [EMAIL PROTECTED] wrote: > [snip] > Tis SQL > > SELECT value > FROM element_values > WHERE user = $user_id > AND(element=48 > OR element=52 > OR and so on) > [/snip] > > You can also use IN > > SELECT value > FROM element_values > WHERE user = $use

RE: [PHP] is there a more efficient query?

2004-08-06 Thread Jay Blanchard
[snip] Tis SQL SELECT value FROM element_values WHERE user = $user_id AND(element=48 OR element=52 OR and so on) [/snip] You can also use IN SELECT value FROM element_values WHERE user = $user_id AND element IN ('48', '52',...) -- PHP General Mailing List (http://www.php.net/) To un

RE: [PHP] is there a more efficient query?

2004-08-06 Thread James Lobley
Hi Brian, Assuming you have mysql 4.0.0 or up, I think the following query should do you: $query2 = "(SELECT value FROM element_values WHERE element=48 AND user=$user_id) UNION (SELECT value FROM element_values WHERE element=49 AND user=$user_id) UNION (SELECT value FROM element_v

RE: [PHP] is there a more efficient query?

2004-08-06 Thread Jay Blanchard
[snip] $query2 = "SELECT value FROM element_values WHERE element=48 AND user=$user_id"; $result2 = mysql_query($query2) or die("could not $query2 " . mysql_error()); list($username) = mysql_fetch_row($result2); [/snip] Tis SQL SELECT value FROM element_values WHERE user = $user_id AND(ele