alena1347 Posted March 15, 2013 Share Posted March 15, 2013 Sorry this could sound simple but not getting it. I need help on writing mysql query $sql=mysql_query("SELECT * FROM TABLE WHERE id = ("some array")"); the above query need to be run with id matches with a array of values,the array is say not of definite size. please could someone help Link to comment https://forums.phpfreaks.com/topic/275690-select-query-help/ Share on other sites More sharing options...
Barand Posted March 15, 2013 Share Posted March 15, 2013 example $sql=mysql_query("SELECT * FROM TABLE WHERE id IN (1,2,3)"); $list = join(',', $somearray); $sql = "SELECT * FROM TABLE WHERE id IN ($list)"; Link to comment https://forums.phpfreaks.com/topic/275690-select-query-help/#findComment-1418820 Share on other sites More sharing options...
alena1347 Posted March 18, 2013 Author Share Posted March 18, 2013 example $sql=mysql_query("SELECT * FROM TABLE WHERE id IN (1,2,3)"); $list = join(',', $somearray); $sql = "SELECT * FROM TABLE WHERE id IN ($list)"; But the above will select just id 1 I need the data of all three Link to comment https://forums.phpfreaks.com/topic/275690-select-query-help/#findComment-1419272 Share on other sites More sharing options...
DaveyK Posted March 18, 2013 Share Posted March 18, 2013 As barand stated: $sql=mysql_query("SELECT * FROM TABLE WHERE id IN (1,2,3)"); this will return 3 results (if they exists), where id = 1 OR id = 2 OR id = 3. However, Barand, wouldn't this: $sql = "SELECT * FROM TABLE WHERE id IN ($list)"; require an implode() ? Link to comment https://forums.phpfreaks.com/topic/275690-select-query-help/#findComment-1419321 Share on other sites More sharing options...
Barand Posted March 18, 2013 Share Posted March 18, 2013 Yes. See my reply #2. join and implode are the same Link to comment https://forums.phpfreaks.com/topic/275690-select-query-help/#findComment-1419374 Share on other sites More sharing options...
DaveyK Posted March 18, 2013 Share Posted March 18, 2013 Oh sorry barand, I totally missed that. Link to comment https://forums.phpfreaks.com/topic/275690-select-query-help/#findComment-1419392 Share on other sites More sharing options...
alena1347 Posted March 20, 2013 Author Share Posted March 20, 2013 As barand stated: $sql=mysql_query("SELECT * FROM TABLE WHERE id IN (1,2,3)"); this will return 3 results (if they exists), where id = 1 OR id = 2 OR id = 3. However, Barand, wouldn't this: $sql = "SELECT * FROM TABLE WHERE id IN ($list)"; require an implode() ? thank you was missing something this solved it. Link to comment https://forums.phpfreaks.com/topic/275690-select-query-help/#findComment-1419745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.