savagenoob Posted September 9, 2010 Share Posted September 9, 2010 Can anyone see why this isnt pulling all the rows that are in the database? $empget = mysql_query("SELECT * FROM members WHERE office = '$office' AND agency = '$agency'") or die(mysql_error()); $emp = mysql_fetch_array($empget); $emplist[] = $emp['member_id']; print_r($emplist); $emplist should contain 3 entries but the print_r is only showing 1. Quote Link to comment https://forums.phpfreaks.com/topic/212993-array-help/ Share on other sites More sharing options...
Adam Posted September 9, 2010 Share Posted September 9, 2010 mysql_fetch_array only returns 1 row at a time, you need to loop through it: while ($emp = mysql_fetch_array($empget)) { print_r($emp); } Quote Link to comment https://forums.phpfreaks.com/topic/212993-array-help/#findComment-1109300 Share on other sites More sharing options...
mikosiko Posted September 9, 2010 Share Posted September 9, 2010 because you are reading only the first result and nothing else your code should be something like $empget = mysql_query("SELECT * FROM members WHERE office = '$office' AND agency = '$agency'") or die(mysql_error()); while ($emp = mysql_fetch_array($empget)) { $emplist[] = $emp['member_id']; } print_r($emplist); the last line will print the complete array... if you want to work with that array you need to do it with a loop (for loop or foreach) Quote Link to comment https://forums.phpfreaks.com/topic/212993-array-help/#findComment-1109303 Share on other sites More sharing options...
savagenoob Posted September 9, 2010 Author Share Posted September 9, 2010 ugh... thank you. Quote Link to comment https://forums.phpfreaks.com/topic/212993-array-help/#findComment-1109304 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.