rahjiggah Posted September 23, 2011 Share Posted September 23, 2011 Hello just wondering if someone can help me... I have a select multiple form that sends the id numbers of records I want to get... how do I construct the query to the mysql db to do this? $array-$_POST['form-array'] so something like $r = ("SELECT column from 'Table' WHERE ID = (array, values, here)") Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/247733-query-db-for-records-with-an-array-of-ids/ Share on other sites More sharing options...
DavidAM Posted September 23, 2011 Share Posted September 23, 2011 If the ID column is a numeric type, the answer is rather simple: $ids = array(2, 4, 8, 16); $sql = 'SELECT columnName from TableName WHERE ID IN (' . implode(',', $ids) . ')'; If the column is a string type, you just have to add a couple of quotes in the right places: $ids = array('I2', 'D4', 'T8', 'Q16'); $sql = 'SELECT columnName from TableName WHERE ID IN ("' . implode('","', $ids) . '")'; Quote Link to comment https://forums.phpfreaks.com/topic/247733-query-db-for-records-with-an-array-of-ids/#findComment-1272158 Share on other sites More sharing options...
rahjiggah Posted September 24, 2011 Author Share Posted September 24, 2011 awesome DavidAM Thanx so much... Quote Link to comment https://forums.phpfreaks.com/topic/247733-query-db-for-records-with-an-array-of-ids/#findComment-1272303 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.