I have a database that contains 11 data in data_employees table.
First , I create the functions and loop the data , store to the array $id,$name
At outside the function, i want use data that store in array.
What happen is $id array only store 1 data instead of 11 data.
Here is my code
<?php require 'connection.php'; function QueryDatabase($option){ global $id, $name; if($option == "selectAll"){ $sql = "select * from data_employees"; $query = mysql_query($sql); $rowCount = mysql_num_rows($query); echo $rowCount; //$rowCount: 11 $i=0; while ($fieldName = mysql_fetch_assoc($query)){ /* store data in array */ $id = array($i => $fieldName['id']); $name = array($i => $fieldName['name']); $i++; echo "<br>".count($id); } } } QueryDatabase('selectAll'); /* I want to loop array outside from the functions */ //display array count, for testing print "<br>count array out from the function :" . count($id); //count($id) = 1 , but the actual number of data is 11 // display all the value in array here foreach ($id as $i => $value) { echo "<br>value of array:"; print_r ($value); } ?>
I am new user in PHP, just tell me what to do.
Thanks for your help.