我创建了一个带有嵌套 select 语句的 mysql seect 语句。现在我的 mysql 技能(或缺乏)非常有限。下面是我写的代码。我得到空白结果或警告。 mysql_fetch_Array 错误。现在我收到一条错误,提示“子查询返回超过 1 行”,任何人都可以为我指明如何开始解决此问题的正确方向。感谢您的帮助。
<?php
session_start();
$memberId = $_GET['id'];
$loggedId = $_SESSION['id'];
include('../connect_DB.php');
$sql = 'SELECT bins.tag_Id, tagging_Info.plant_Id, tagging_Info.photo_Id FROM bins inner join tagging_Info on bins.tag_Id = tagging_Info.tag_Id inner join collections on collections.id = bins.collection_Id WHERE collections.member_Id ='.$memberId.' and collections.id=(SELECT id FROM collections where member_Id='.$memberId.')';
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$collection = "Success"; // test to see if working
}
echo $collection;
?>
最佳答案
您是否尝试过仅执行子查询来查看实际返回了多少条记录并确保实际设置了 $memberId?
用户拥有多个集合是有意义的,因此您可能应该调整主查询以在子查询结果上使用 IN 而不是 = 。
关于php - Mysql 嵌套查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12752930/