Querying a database for 50 users' information: 50 queries or a WHERE array?
| From: | Dotan Cohen | Date: | Tue, 13 Sep 2011 14:24:59 +0000 |
| Subject: | Querying a database for 50 users' information: 50 queries or a WHERE array? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-314790@lists.php.net to get a copy of this message | ||
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