dreamwest Posted May 31, 2009 Share Posted May 31, 2009 Im trying to select an array of rows. I need to select all rows with different ids: id | name 234 | name1 3 |name2 125 |name3 4 |name4 $query = "SELECT * FROM table WHERE id=(4,125) and approve=1 "; So im selecting everything from row 4 and 125....but syntax error I cant think how to do it.. Quote Link to comment https://forums.phpfreaks.com/topic/160344-select-values/ Share on other sites More sharing options...
roopurt18 Posted May 31, 2009 Share Posted May 31, 2009 $query = "SELECT * FROM table WHERE id in (4,125) and approve=1 "; Quote Link to comment https://forums.phpfreaks.com/topic/160344-select-values/#findComment-846138 Share on other sites More sharing options...
dreamwest Posted May 31, 2009 Author Share Posted May 31, 2009 Sweet! Thanks I found another way too, would this way cause any problems $query = "SELECT * FROM table WHERE (id=4 || id=125) and approve=1 "; Quote Link to comment https://forums.phpfreaks.com/topic/160344-select-values/#findComment-846140 Share on other sites More sharing options...
roopurt18 Posted May 31, 2009 Share Posted May 31, 2009 It won't cause problems. But in SQL it's probably "more" correctly to use OR instead of || $query = "SELECT * FROM table WHERE (id=4 OR id=125) and approve=1 "; The IN( ... ) method is probably easier to code in PHP as well with arrays and implode. Quote Link to comment https://forums.phpfreaks.com/topic/160344-select-values/#findComment-846155 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.