flemingmike Posted March 2, 2011 Share Posted March 2, 2011 hello, have a question. im trying to do a select * where id exists in array $id8 here is my array $result8 = mysql_query("SELECT * FROM customers WHERE whosclient = 'Lansoft'"); while($row8 = mysql_fetch_array($result8)) { $id8=$row8['id']; } here is my select code. it is only returning results for the highest number in the array $result = mysql_query("SELECT * FROM timesheets WHERE status = 3 AND billable = 1 AND client = '$id8' ORDER BY date, starttime"); while($row = mysql_fetch_array($result)) { Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/229407-select-if-id-exists-in-array/ Share on other sites More sharing options...
doddsey_65 Posted March 2, 2011 Share Posted March 2, 2011 im no expert but ill give it a shot: $id8 = array(); $result8 = mysql_query("SELECT * FROM customers WHERE whosclient = 'Lansoft'"); while($row8 = mysql_fetch_array($result8)) { $id8[].=$row8['id']; } $result = mysql_query("SELECT * FROM timesheets WHERE status = 3 AND billable = 1 AND client = '".in_array($id8)."' ORDER BY date, starttime"); while($row = mysql_fetch_array($result)) { That what you were after? Link to comment https://forums.phpfreaks.com/topic/229407-select-if-id-exists-in-array/#findComment-1181985 Share on other sites More sharing options...
flemingmike Posted March 2, 2011 Author Share Posted March 2, 2011 thanks, but no luck. Link to comment https://forums.phpfreaks.com/topic/229407-select-if-id-exists-in-array/#findComment-1181989 Share on other sites More sharing options...
AbraCadaver Posted March 2, 2011 Share Posted March 2, 2011 Almost right: $id8 = array(); $result8 = mysql_query("SELECT * FROM customers WHERE whosclient = 'Lansoft'"); while($row8 = mysql_fetch_array($result8)) { $id8[] = $row8['id']; // create array } $list = implode(',', $id8); // implode array into comma seperated list to use in the IN clause $result = mysql_query("SELECT * FROM timesheets WHERE status = 3 AND billable = 1 AND client IN ($list) ORDER BY date, starttime"); Link to comment https://forums.phpfreaks.com/topic/229407-select-if-id-exists-in-array/#findComment-1182005 Share on other sites More sharing options...
AbraCadaver Posted March 2, 2011 Share Posted March 2, 2011 Typo, should be: client IN ($list) Link to comment https://forums.phpfreaks.com/topic/229407-select-if-id-exists-in-array/#findComment-1182009 Share on other sites More sharing options...
flemingmike Posted March 2, 2011 Author Share Posted March 2, 2011 awesome. thanks! Link to comment https://forums.phpfreaks.com/topic/229407-select-if-id-exists-in-array/#findComment-1182016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.