MySQL Forums
Forum List  »  PHP

Nested JSON in PHP
Posted by: Jassm Rahma
Date: July 08, 2017 08:57AM

Hi,

I have this SQL:

SELECT customers_address.customer_address_id, address_category.address_category_name, customers_address.address_name,
address_details.address_details_id, address_details.address_details_text
FROM customers_address
JOIN address_category ON address_category.address_category_id = customers_address.address_category_id
LEFT JOIN address_details ON address_details.customer_address_id = customers_address.customer_address_id
WHERE customer_id = param_customer;

I want to display an output JSON like this in PHP:

{
"Address": {
"customer_address_id": "customer_address_id",
"address_category_name": "address_category_name",
"address_name": "address_name",
"Details": [{
"address_details_id": "address_details_id",
"address_details_text": "address_details_text"
},
{
"address_details_id": "address_details_id",
"address_details_text": "address_details_text"
},
{
"address_details_id": "address_details_id",
"address_details_text": "address_details_text"
}
]
}
}

The same customer_address_id might have one or more branches as you can see.

Kindly help..


Thanks,
Jassim

Options: ReplyQuote


Subject
Written By
Posted
Nested JSON in PHP
July 08, 2017 08:57AM
September 04, 2017 03:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.