Jump to content

Array help


savagenoob

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/212993-array-help/
Share on other sites

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)

Link to comment
https://forums.phpfreaks.com/topic/212993-array-help/#findComment-1109303
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.