0

I have 4 tables, in table's 'tbl_Order' has single record of each cusotmer. in table's 'tbl_OrderDetail' there are more then 1 Services (records) of each customer. in table's 'tbl_services' there are more then 10 pre-define services. inch table's 'tbl_users' there are customer's basic information.

my question is : how I can fetch data by each customer using PHP with MySql. My tables details are below:

tbl_Order:   Order_ID,Order_Type,Order_Date,Time,Customer_ID,Booking_Type,Booking_Status,Order_No,Car_No,Booking_Date

tbl_OrderDetail: ID,Order_ID,Service_ID     

tbl_services :  Service_ID,S_Name,S_Price

tbl_users : Customer_ID ,User_Name
Nalaka526
  • 11,278
  • 21
  • 82
  • 116
  • 2
    We're not here to write code for you. Please show what you've tried so far, and explain why it isn't working for you. There's nothing tricky about joining 4 tables, it's the same as joining 2 tables except you do it 2 more times. – Barmar Jul 11 '13 at 02:56
  • Since you are new here, accept the answer(tick) which solved your problem. Up-vote(up arrow) the answer(s) which give(s) you information or help(s) you. Down-vote(down arrow) the answer(s) which are fake. – Techie Jul 11 '13 at 03:11

2 Answers2

0

you can join four tables using primary key of one table with forign key of other table and at the of the query just use order by User_Name

0
select *
from
    tbl_Order a
        inner join
    tbl_OrderDetail b
        on a.Order_ID = b.Order_ID
        inner join 
    tbl_services  c
        on b.Service_ID = c.Service_ID
    tbl_users  d
        on d.Customer_ID = c.Customer_ID

I would advice you to select the columns you want instead of using *. E.G : a.Order_ID, b.Service_ID

Read more

Community
  • 1
  • 1
Techie
  • 44,706
  • 42
  • 157
  • 243