我写了一个MySQL查询:
$feedItem->tags =
$result = mysqli_query("SELECT *
FROM qzxh_k2_tags, qzxh_k2_tags_xref
WHERE qzxh_k2_tags.id = qzxh_k2_tags_xref.tagID
AND qzxh_k2_tags.id = '406'
AND qzxh_k2_tags_xref.itemID = '".$item->id"'");
while($tag = mysqli_fetch_array($result))
echo $tag;
查询本身在PHPMyAdmin中显示了我需要的结果,但由于某种原因,在PHP中使用时没有显示任何内容。有什么想法,我出错了吗?
答案 0 :(得分:3)
您缺少连接运算符(点)
更改
"SELECT *
FROM qzxh_k2_tags, qzxh_k2_tags_xref
WHERE qzxh_k2_tags.id = qzxh_k2_tags_xref.tagID
AND qzxh_k2_tags.id = '406'
AND qzxh_k2_tags_xref.itemID = '".$item->id"'"
// You are missing dot . here ^
到
"SELECT *
FROM qzxh_k2_tags, qzxh_k2_tags_xref
WHERE qzxh_k2_tags.id = qzxh_k2_tags_xref.tagID
AND qzxh_k2_tags.id = '406'
AND qzxh_k2_tags_xref.itemID = '".$item->id."'"
答案 1 :(得分:2)
在sql查询中使用正确的字符串连接。查找以下更正的查询。
$result = mysqli_query("SELECT *
FROM qzxh_k2_tags, qzxh_k2_tags_xref
WHERE qzxh_k2_tags.id = qzxh_k2_tags_xref.tagID
AND qzxh_k2_tags.id = '406'
AND qzxh_k2_tags_xref.itemID = '".$item->id."'");