我有一个返回项目详细信息的查询。它属于某个类别;因此,我已将 ITEMS 表链接到 CATEGORIES 表,并将外键保存到 ITEMS 表中。
现在,我希望任何选定项目的详细信息也显示类别名称而不是外键。我已经尝试INNER JOIN
如下,但令人惊讶的是,查询仍然显示外键。
这是我的查询:
/* Create the prepared statement */
if ($stmt = $mysqli->prepare("SELECT categories.category AS category,
items.id,
items.name,
items.description
FROM items
INNER JOIN categories
ON categories.cat_id = items.cat_id
WHERE items.id='$id'")) {
/* Execute the prepared Statement */
$stmt->execute();
/* Bind results to variables */
$stmt->bind_result($id,$category,$name,$description);
/* fetch values */
while ($rows = $stmt->fetch()) {
...
}
...
}
输出类别名称:
<?php
echo $category;
?>
这里可能缺少什么?