我在MySQL中使用连接相对较新。
我有两张桌子:
sh_subscriptions
=> id
=> user_id
=> feed_id
sh_feeds
=> id
=> shop_name
=> feed_id
我正在尝试从sh_subscriptions
获取所有字段feed_id
对应于feed_id
对应sh_feed
的{{1}}以及$row['shop_name']
{1}}对应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>";
}
内的任何内容都没有打印出来。
答案 0 :(得分:0)
试试这个:
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));
答案 1 :(得分:0)
我认为应该是
SELECT * FROM sh_subscriptions s
INNER JOIN sh_feeds f ON s.feed_id = f.feed_id
WHERE s.id = '" . $id['id'] . "'
AND f.shop_name = '" . $row['shop_name'] . "';