gpt4 book ai didi

php - MySQL 连接查询似乎有效,但未按预期执行

转载 作者:行者123 更新时间:2023-11-30 00:21:29 25 4
gpt4 key购买 nike

我对在 MySQL 中使用联接还比较陌生。

我有两个表:

sh_subscriptions
=> id
=> user_id
=> feed_id

sh_feeds
=> id
=> shop_name
=> feed_id

我正在尝试从 sh_subscriptions 获取所有字段,其中 feed_id 对应于 sh_feed 中的 feed_id对应于 $row['shop_name'],其中 user_id 对应于 $id['id]

这是我的尝试:

SELECT * FROM sh_subscriptions s
INNER JOIN sh_feeds f ON s.shop_id = f.feed_id
WHERE s.id = '" . $id['id'] . "'
AND f.shop_name = '" . $row['shop_name'] . "'

更新

我现在有以下内容:

while($row = mysqli_fetch_array($query))
{
echo "<div class='col-md-4'>";
echo $row['shop_name'] . " ";
$query = mysqli_query($con, "SELECT * FROM sh_subscriptions s INNER JOIN sh_feeds f ON s.feed_id = f.feed_id WHERE s.user_id = '" . $id['id'] . "' AND f.shop_name = '" . $row['shop_name'] . "'") or die(mysql_error($con));
echo "</div>";
}

我可以确认数据库字段全部存在,并且变量打印正确,但尽管包含了错误处理程序,但 div 内没有任何内容被打印。

最佳答案

试试这个:

SELECT * FROM sh_subscriptions s
INNER JOIN sh_feeds f ON s.id = f.feed_id
WHERE s.id = '" . $id['id'] . "'
AND f.shop_name = '" . $row['shop_name'] . "'") or die(mysql_error($con));

关于php - MySQL 连接查询似乎有效,但未按预期执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23197356/

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