RE: [PHP] Querying a database for 50 users' information: 50 queries or a WHERE array?
| From: | Ashley Sheridan | Date: | Tue, 13 Sep 2011 14:44:34 +0000 |
| Subject: | RE: [PHP] Querying a database for 50 users' information: 50 queries or a WHERE array? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-314796@lists.php.net to get a copy of this message | ||
yeer tai <yeertai@hotmail.com> wrote:
>
>
>select * from table where userID in(1,2,3,etc)
>
>
>
>> From: ash@ashleysheridan.co.uk
>> Date: Tue, 13 Sep 2011 15:29:26 +0100
>> To: dotancohen@gmail.com; php-general@lists.php.net
>> Subject: Re: [PHP] Querying a database for 50 users' information: 50
>queries or a WHERE array?
>>
>>
>>
>> Dotan Cohen <dotancohen@gmail.com> wrote:
>>
>> >I have a MySQL database table with about 10,000 rows. If I want to
>> >query for 50 specific users (so no LIMIT ORDER BY) then I seem to
>have
>> >these choices:
>> >
>> >1) SELECT * FROM table
>> >This will pull in all 10,000 rows, not nice!
>> >
>> >2) foreach ($user as $u) { mysql_query("SELECT * FROM table WHERE
>> >userID=".$u); }
>> >This will lead to 50 queries, again not nice! (maybe worse)
>> >
>> >3) foreach ($user as $u) { $whereClause+=" OR userID=".$u; }
>> >This makes a huge SQL query. However, this is the method that I'm
>using
>> >now.
>> >
>> >Is there some sort of array that can be passed in the WHERE clause,
>> >containing all the userID's that I am interested in?
>> >
>> >Thanks!
>> >
>> >--
>> >Dotan Cohen
>> >
>> >http://gibberish.co.il
>> >http://what-is-what.com
>> >
>> >--
>> >PHP General Mailing List (http://www.php.net/)
>> >To unsubscribe, visit: http://www.php.net/unsub.php
>>
>> SELECT * FROM table WHERE userID IN (1,2,3,4,5,etc)
>>
>> Much smaller than what you proposed in #3, and easier to make if your
>user is list is already an array.
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>> --
>> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php..net/unsub.php
>>
>
Erm, that's funny that you replied with the exact same answer as I gave, just top-posted on my
reply...
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.