2015-05-19 81 views
1

我正在開發酒店管理系統。我在結帳頁面遇到問題。顯示php mysql的重複數據

我想顯示已預訂房間並在結帳清單中的所有用戶。當用戶預訂一個房間時它正在工作。如果用戶預留兩個或多個房間,那麼記錄重複我不想要的。

這是我從哪裏獲取數據的查詢。

SELECT 
    c.client_id, c.client_name, c.guests, c.address, c.no_of_rooms, 
    b.booking_id, rb.rb_id, rb.check_in_date, rb.check_out_date, rb.room_no, 
    t.total_price, t.extra_person, t.extra_amount, t.advance_amount, 
    t.remaining_amount, t.payment_status, t.discount, t.payment_type, t.transaction_id 
FROM `clients` c, `booking` b, `rooms` r, `room_booking` rb, `transactions` t 
WHERE r.room_status = 'Reserved' 
    AND 
    r.room_no = rb.room_no 
    AND 
    c.client_id = b.client_id 
    AND 
    b.booking_id = rb.booking_id 
    AND 
    b.booking_id = t.booking_id 
    AND 
    rb.check_out_date BETWEEN '$today' AND '$next_day' 

我在這裏展示誰是結賬的記錄是今天(今$)併爲未來30天($ nextday)

+0

請永遠格式化你的代碼。 – dbndhjefj

回答

2

您當前的查詢提取所有從一個房間預留客房詳情預訂表,如果用戶預留了多個房間,那麼顯然該條目將被顯示,並且您將以兩個條目獲取該用戶,爲了只有那些處於結帳列表中的用戶,您需要按客戶端ID對查詢進行分組,以便您獲取所有要結帳的用戶。

更新查詢

SELECT 
    c.client_id,  
    c.client_name, 
    c.guests, 
    c.address, 
    c.no_of_rooms, 
    b.booking_id, 
    rb.rb_id, 
    rb.check_in_date, 
    rb.check_out_date, rb.room_no, 
    t.total_price, 
    t.extra_person, 
    t.extra_amount, 
    t.advance_amount, 
    t.remaining_amount, 
    t.payment_status,t.discount, 
    t.payment_type, 
    t.transaction_id 
FROM 
`clients` c, 
`booking` b, 
`rooms` r, 
`room_booking` rb, 
`transactions` t 
WHERE 
    r.room_status = 'Reserved' 
    and 
    r.room_no = rb.room_no 
    and 
    c.client_id = b.client_id 
    and 
    b.booking_id = rb.booking_id 
    and 
    b.booking_id = t.booking_id 
    and 
    rb.check_out_date BETWEEN '$today' AND '$next_day' 
GROUP BY 
    c.client_id 
+0

但是在那種情況下,我只有一個用戶房間,我已經做了 –

+0

您可以通過在select子句中添加聚合函數(如「count(c.no_of_rooms)」)來獲得該用戶的總房間數。 –

+0

我已經收到了房間的號碼,但問題是,我也必須得到房間號碼,以便我可以相應地釋放那些房間 –