$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']
)
}
表人
id
表格工作
id
在上面的代码中,我正在两个表之间进行内部连接。两个表都有一个名为id
的列,是否有办法区分while loop
中的两个?
我已经尝试了上述内容但$row['j.id']
不起作用,如果我$row['id']
,则它会将id
和job_id
写入相同的值。
答案 0 :(得分:10)
$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']
);
}