gpt4 book ai didi

php - mysqli_fetch_assoc 循环不从数据库写入任何内容

转载 作者:行者123 更新时间:2023-11-29 11:57:56 24 4
gpt4 key购买 nike

这段代码的目的是在帖子上写出评论,所以如果Itemid匹配它会将其写在帖子下方,但它不会写任何内容。

$query2 = "select * from Comments inner join Items where Comments.Itemid = Items.Itemid order by date desc";
$result2 = mysqli_query($link, $query2);

while ($commentrow = mysqli_fetch_assoc($result2)) {
echo "<div class='svar'>";
echo "<p> inlägg av:" . "<a href=profil.php?key=" . $commentrow['Userid'] . ">" . $commentrow['Name'] . "</a> " . " " . $commentrow['Date'] . "</p>";
echo "<p>" . $commentrow['Item'] . "</p>";
}

最佳答案

您的 INNER JOIN 中存在错误,请将 WHERE 替换为 ON

$query2 = "select * from Comments inner join Items where Comments.Itemid = Items.Itemid order by date desc";

应该是

$query2 = "SELECT * FROM Comments INNER JOIN Items ON Comments.Itemid = Items.Itemid ORDER BY date DESC";

Reference

备用

您尝试的方式,可以不用 INNER JOIN 像这样使用 WHERE 子句

$query2 = "SELECT * FROM Comments, Items WHERE Comments.Itemid = Items.Itemid ORDER BY date DESC";

旁注:仍然对查询原因 ORDER BY date 存有疑问,因为当您在循环日期中获取数据时,这里的 capitol Date $commentrow[ 'Date'],哪一个是正确的我的猜测应该是 ORDER BY Date 并且缺少表名,应该是 ORDER BY tablname.Date where tablename可以是 CommentsItems 取决于哪个具有 Date col

关于php - mysqli_fetch_assoc 循环不从数据库写入任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32896126/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com