Reputation: 868
Hello i have a problem with the logic to have a multidimentional array for each while loops that i had. I do not know why is it not working.
i wanted to have like this as concept
data >
ser_id > 14
org_name > "org a"
ser_id > 15
org_name > "org b"
but the output is like this
Array
(
[data] => Array
(
[ser_id0] => 14
[0] => Array
(
[0] => Gannon University
)
[ser_id1] => 15
[1] => Array
(
[0] => Lions Club
)
[ser_id2] => 16
[2] => Array
(
[0] => Rotatory Club
)
)
)
Can you help me with the logic. Here is the code i worked on with rows loop fetched from db.
$rs = $this->crud->fetchResultSet("services");
$rows = array();
$i=0;
while($row = $rs->fetch_assoc()){
//$rows = arra
$ser_id = $row["ser_id"];
$rows["data"][$i] = $ser_id;
$orgrs = $this->crud->fetchSingleResultSet("organizations","ser_id",$row['ser_id']);
$j=0;
while($innrow = $orgrs->fetch_assoc()){
$rows["data"][$i][$j] = $innrow["org_name"];
$j++;
}
$i++;
}
Upvotes: 1
Views: 50
Reputation: 1637
use multidimensional array like this =>>
$a[$i]['ser_id']=$row["ser_id"];
$a[$i]['org_name']=$innrow["org_name"]
and restore data like this
$max=count($a[$i]);
for($i=0;$i<$max;$i++){
echo 'ser_id =>'.$a[$i]['ser_id'];
echo 'org_name =>'.$a[$i]['org_name'];
}
Upvotes: 2