0

我有一个正在构建的汽车预订系统数据库。我有 3 张桌子:

车表:

ID     | car_make | car_name
1      | Ford     | Focus
2      | BMW      | Z3
3      | Audi     | A5

预订表:

booking_ID  | booking_time | total_cost | etc..
125674      | 2013-02-02   | 91.55     
887463      | 2013-01-19   | 52.00     
209930      | 2013-01-11   | 23.99  

预订表:

ID     | booking_ID | car_ID
1      | 125674     | 2
2      | 887463     | 2
3      | 209930     | 1

因此,reservation_table 将汽车与预订联系起来。现在我想在表格中为用户输出以下结果:

booking_ID | booking_time | total_cost | car_ID | car_make | car_model 

我如何输出结果,到目前为止,我几乎可以正常工作:

$query = " 
SELECT 
    booking_ID, 
    total_cost, 
    booking_time, 
    customer_ID,
    car_ID
FROM 
    bookings_table as bb,
    reservation_table as br 
WHERE 
    bb.booking_ID = br.booking_ID AND
    payment_success=true   
ORDER BY 
    booking_ID desc 
LIMIT 
    10
";

try { 
    $stmt = DB::get()->prepare($query); 
    $stmt->execute(); 

    $rows = $stmt->fetchAll();
}  
catch(PDOException $ex) { 
    // Failed 
} 

foreach($rows as $row):
    <td>'.$row['booking_ID'].'</td>
    etc...
endforeach;

显示如下:

booking_ID | booking_time | total_cost | car_ID | car_make | car_model 
125674     | 2013-02-02   | 91.55      | 2      |          |  

所以我可以从reservation_table 中获取car_ID,但我不知道如何通过从reservation_table 中获取car_ID 来提取car_make/model。

4

0 回答 0