$q = $db->query("SELECT *
FROM people p
INNER JOIN job j
ON p.job_id = j.id
WHERE p.id = '$id'
ORDER BY j.id ASC");
$maps = array();
while($row = mysqli_fetch_array($q)) {
$product = array(
'id' => $row['id'],
'job_id' => $row['j.id']
)
}
table people
id
table job
id
In the above code I am doing an inner join between two tables. Both tables have an a column called id
is there a way to differentiate between the two in my while loop
?
I have tried the above but $row['j.id']
doesn't work and if I do $row['id']
then it writes both id
and job_id
with the same value.
$q = $db->query("SELECT *, j.id as jid, p.id as pid
FROM people p
INNER JOIN job j
ON p.job_id = j.id
WHERE p.id = '$id'
ORDER BY j.id ASC");
$maps = array();
while ($row = mysqli_fetch_array($q)) {
$product = array(
'id' => $row['pid'],
'job_id' => $row['jid']
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With