0

My table

My Post array

How do i fetch multidimensional array data in my table. As per in my image foodname, quantity, price should be fetch in my table.

glennsl
  • 28,186
  • 12
  • 57
  • 75

1 Answers1

0

Let's assuming that you have the relationships set up in here. Basically you would have on the food table: quatity_id and price_id. Having the relationships we just need to do a join:

select * from `food_table` where `food` = `Super man's soupe` join `quantity_table` where `food_table.quantity_id` = `food_table.id` join `price` where `food_table.price_id` = `food_table.id`

A join assumes that you have all the data otherwise it will throw you an error. Let's suppose you have another food called Batman's soup but you wouldn't have the price because you know... Batman has a shit ton of money. You would receive an error because you were trying to join a column that does not exists. For cases like this we need to use leftjoin.

Difference in MySQL JOIN vs LEFT JOIN

Bruno Francisco
  • 3,841
  • 4
  • 31
  • 61