简体   繁体   中英

Inner Join 3 Tables in PHP

I'm trying to develop a management system as a part of my thesis.

Question: What is wrong with the following query?

$query = "SELECT ab.bloodtype, dep.date_donated, dep.amount, sr.
        first_name, sr.last_name, loc.location_name
    FROM deposits AS dep 
    INNER JOIN donorstb AS sr ON dep.donor_id = sr.donorID 
    INNER JOIN available_blood AS ab ON dep.blood_id = ab.blood_id 
    INNER JOIN location AS loc ON dep.location_id = loc.location_id 
    ORDER BY donorID DESC;"

The desired output is something like the following:

Firstname | Lastname |    Date Donated    | Donated at | Bloodtype | Amount

Ron       | Flores   |  November 18,2017  |   Vigan    |    B+     | 2units

You need to share those tables. Whatever I just edit your code. Try It -

$query = "SELECT sr.first_name as Firstname, sr.last_name as Lastname, dep.date_donated as 'Date Donated', loc.location_name as 'Donated at', ab.bloodtype as Bloodtype, dep.amount as Amount
FROM deposits AS dep
INNER JOIN donorstb AS sr ON dep.donor_id = sr.donorID
INNER JOIN available_blood AS ab ON dep.blood_id = ab.blood_id
INNER JOIN location AS loc ON dep.location_id = loc.location_id
ORDER BY sr.donorID DESC;"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM