I have a many to one problem, I have data organized in mysql like:
>order1 : mycustomer : item1
>order1 : mycustomer : item2
>order2 : mycustomer : item3
>order2 : mycustomer : item1
>order3 : mycustomer : item2
I want to create the JSON something like (for explanation purposes)
>order1 mycustomer
>> item1
>> item2,
>order2 mycustomer
>> item3
>> item1,
>order3 mycustomer
>> item2
But my looping is not correct, I am not getting the order with item array then repeat for next order. What am I doing wrong.
$query = "SELECT * from `orders` WHERE proc = 'N'";
$result = $conn->query($query);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$onum = $row['order_number'];
foreach($result as $results)
{
$quantity_invoiced = $row[quantity_invoiced];
$unit_price = $row[unit_price];
$item_description = $row['item_description'];
$itemed = $results['item_description'];
echo $itemed;
$tx_data[] = [
"partnerRef" => $onum,
"lines" => $itemed
];
}
}
$flagupdate = "UPDATE `orders` SET proc = 'Y' where proc = 'N'";
myqueryi_query($conn, $flagupdate);
} else {
echo "no results";
}
echo json_encode($tx_data);