boy2020 boy2020 - 9 days ago 6
PHP Question

How create array from invoice data and items with php and mysql for Angularjs

Is it good way for create array from invoice data and invoice items with php and mysql for Angularjs or i can mix two query inside one query and make this array variable ?

I want have array with this elemets

id
,
payPrice
,
payStatus
,
clientAddress
and nested array with
items
that contant invoice intems data.

$result = $db->query("select `id`,`payPrice`,`payStatus`,`clientAddress`
from `invoice` where `clientId`=22");
if($result && $result->num_rows>0){
if($row=$result->fetch_assoc()){

$result1 = $db->query("select * from `invoice_items` where `invoiceId`=". $row['id']);
if($result1 && $result1->num_rows>0){
$row["items"]=$result1;
return $row;
}else{return false;}

}else{return false;}
}else{return false;}

Answer

Yes, i think you selected good techniqe for make array from tables . Because if you join two table together each row contain two table columns and you can't nested.