[英]PHP MySQL inner join with same column name
$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
? 两个表都有一个名为id
的列是否有办法区分我的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. 我已经尝试了上面但$row['j.id']
不起作用,如果我执行$row['id']
那么它会将id
和job_id
写入相同的值。
$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']
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.