Reputation: 543
I am trying to get value of foreign key in my view. But i don't know how to do that. My table structure is like: requisition:
requisition_approval
I got all values from the requisition table with:
$qry = "SELECT * FROM requisition where created_by = '$uid'";
$result = $this->fetch($qry);
return $result;
But it will return id in foreign key values. I want to get name of user from users table and approval status from the requisition_approval table. How can i do that?
Upvotes: 0
Views: 279
Reputation: 1833
You are looking to learn about JOINS
:
SELECT R.*, U.*
FROM requisition R
LEFT JOIN users U ON R.created_by=U.id
WHERE R.created_by = '$uid'";
From your example, requisition_approval
table is not clearly linked. You need a common field
Upvotes: 1