0

I have 3 Tables With Following Structure!

Delivery_Boy : id(PK), date, time, comment, order_id,

Order_history : order_history_id(PK), order_id, order_status_id,

Order_status : order_status_id(PK), status_name

Requirement: Delivery_boy table contains orders each having unique order_id. But the order_status_id or Status_name is not Available in this Table.

I want to join the order_history and order_status table, so that they produce status_name for corresponding order_status_id and display it as a column in delivery_boy table.

Currently my Code is:

    public function getOrder($username) {
    $query = $this->db->query("SELECT date, time, oh.order_id, oh.comment, os.order_status_id AS status FROM delivery_boy oh LEFT JOIN ". DB_PREFIX . "order_history os ON oh.order_id = os.order_id WHERE name = '" . $this->db->escape($username) . "'");
    return $query->rows;
}

And I get the result like in the below image: It only shows the status_id, not the status_name.

I have tried but can't figure out. Please help! enter image description here

Harish ST
  • 1,475
  • 9
  • 23
  • 1
    Looks like you need a second LEFT JOIN on order_status, to bring that in. – IncredibleHat Jul 09 '18 at 12:32
  • Thank you @IncredibleHat. How can I Use Second LEFT JOIN to Connect the Other two Tables? I am Totally Confused! – Harish ST Jul 09 '18 at 12:33
  • 1
    Well, I was writing your SQL example in an answer, but the question got closed, so you'll have to derive it from that other answer in the dupe !. – IncredibleHat Jul 09 '18 at 12:35
  • I tried it a lot and only after that I have made this question here! But :( – Harish ST Jul 09 '18 at 12:39
  • There are dozens of questions here on SO that deal with joining three tables, so another one does not add much value. That duplicates I linked contain not only code in the answers, but explanations as well. – Shadow Jul 09 '18 at 12:48
  • Ok. I am trying With Those... @Shadow – Harish ST Jul 09 '18 at 12:49

0 Answers0