Select data from 2 PHP tables

Asked

Viewed 44 times

0

Good people, I have here two tables with the following structure:
1 - Orders, 2 - Order_items.
inserir a descrição da imagem aqui Order Items

I need to select the data of each and display the purchase details, example:
Order #1 (table 1)
Client: Thales (table 1)
Snacks: snack 1, snack 2, snack 3 (table 2) (value of each snack in table 2)
Address: Customer’s address (table 1)
Payment: Payment (table 1)
Status: Received (table 1)

Total: total value (calculate from table 2)

How could I do that? I’ve made several attempts, but I’m not being able to display correctly.

  • You can make this query in SQL and bring it to PHP. How do you query the BD?

  • I’m using SELECT pedidos.id, pedidos.client_id, pedidos.valor, pedidos.status, order_items.lanche_id, order_items.client_id FROM pedidos LEFT JOIN order_items ON order_items.client_id = pedidos.client_id GROUP BY pedidos.id DESC LIMIT 1 However, in snacks for example, even if I have more than one, I get only one. (Ex: Customer bought snacks 1, snacks 2, snacks 3. I get return only snack 1)

  • you are using the DESC LIMIT 1, eliminate the LIMIT 1 and run again.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.