On Tue, Sep 13, 2011 at 2:06 PM, Steve Staples <sstaples@xxxxxxxx> wrote: > On Tue, 2011-09-13 at 09:48 -0700, David Harkness wrote: > > On Tue, Sep 13, 2011 at 7:29 AM, Ashley Sheridan > > <ash@xxxxxxxxxxxxxxxxxxxx>wrote: > > > > > SELECT * FROM table WHERE userID IN (1,2,3,4,5,etc) > > > > > > > +1. And this is a great place to use implode(): > > > > $sql = 'select ... where userID in (' . implode(',', $ids) . ')'; > > > > David > > I mentioned that implode earlier, but there is also the underlying > question (which I also asked earlier)... how is he getting the 50 id's > to populate? > > here are 2 other ways of skinning the cat: > > using an inner join: > select table.* from table inner join othertable on (table.userid = > othertable.userid) where (use the way your getting the 50 id's here); > > OR by using a subselect, > select * from table where userid IN (select group_concat(userid, > separator ', ') FROM othertable where (using logic here)); > > guess it all depends on how you want to do it... but that would make it > 1 db query > > good luck! > > > -- > > Steve Staples > Web Application Developer > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > And this will be faster or at least more efficient with a limit (e.g. limit 50) this way when you have found the 50 users in the "in" statement, you don't continue iterating through the rest of your data set... -- The trouble with programmers is that you can never tell what a programmer is doing until it’s too late. ~Seymour Cray