Re: Querying a database for 50 users' information: 50 queries or a WHERE array?

From: Date: Tue, 13 Sep 2011 19:39:56 +0000
Subject: Re: Querying a database for 50 users' information: 50 queries or a WHERE array?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-314813@lists.php.net to get a copy of this message
On Tue, Sep 13, 2011 at 17:34, Steve Staples <sstaples@mnsi.net> wrote: > what criteria are you using to get the "stats" for these 50 users? > They are passed as an array into a function I'm cleaning up. > also, wouldn't this be much better suited for the mysql mailing list? > Yes. > if you know all the userids, then you could just do it as: > > $sql = "SELECT * FROM table WHERE userid IN (". implode(', ', > $usersids) .")"; > > not very elegant, and I am not sure that the IN is any better than doing > 50 mysql calls, but this is only 1 call, and gets you the data. > This is exactly what I need, thanks! > Are you querying the database to get the id's in the frist place?  if > so, you could look at doing an inner join on the 2 tables. > Actually, I do suspect that is where it's coming from. But the calling function is not in my hands. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com

« previous php.general (#314813) next »