Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP PDO - How to Output Results from Three Tables
    primarykey
    data
    text
    <p>I have a car booking system database that i am in the process of building. I have 3 tables:</p> <p>car_table:</p> <pre><code>ID | car_make | car_name 1 | Ford | Focus 2 | BMW | Z3 3 | Audi | A5 </code></pre> <p>booking_table:</p> <pre><code>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 </code></pre> <p>reservation_table:</p> <pre><code>ID | booking_ID | car_ID 1 | 125674 | 2 2 | 887463 | 2 3 | 209930 | 1 </code></pre> <p>So the reservation_table links the cars with the bookings. Now i am wanting to output the following result in a table for the user:</p> <pre><code>booking_ID | booking_time | total_cost | car_ID | car_make | car_model </code></pre> <p>How can i output the results for this, so far i have this almost working:</p> <pre><code>$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()-&gt;prepare($query); $stmt-&gt;execute(); $rows = $stmt-&gt;fetchAll(); } catch(PDOException $ex) { // Failed } foreach($rows as $row): &lt;td&gt;'.$row['booking_ID'].'&lt;/td&gt; etc... endforeach; </code></pre> <p>Which displays as below:</p> <pre><code>booking_ID | booking_time | total_cost | car_ID | car_make | car_model 125674 | 2013-02-02 | 91.55 | 2 | | </code></pre> <p>So i can get the car_ID from the reservation_table but i don't know how i can also pull out the car_make/model by taking the car_ID from the reservation_table.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload