简体   繁体   English

Mysql嵌套查询麻烦

[英]Mysql Nested Query Trouble

I have created a mysql seect statement with a nested select statement. 我用嵌套的select语句创建了一个mysql seect语句。 Now my mysql skills (or lack there of) are very limited. 现在我的mysql技能(或缺乏)非常有限。 Below is the code that I wrote. 下面是我写的代码。 I was getting blank results or the Warning. 我得到空白结果或警告。 mysql_fetch_Array error. mysql_fetch_Array错误。 Now I am currently receiving an error that says "Subquery returns more than 1 row" Can anyone point me in the right direction on how I can begin to fix this problem. 现在我正在收到一条错误,上面写着“子查询返回超过1行”任何人都可以指出我正确的方向如何开始解决这个问题。 Thanks for the help. 谢谢您的帮助。

 <?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;

?>

Have you tried executing just the subquery to see how many records are actually being returned and to ensure that $memberId is actually set? 您是否尝试仅执行子查询以查看实际返回的记录数,并确保实际设置了$ memberId?

It would make sense for a user to have multiple collections so you should probably adjust your main query to use IN instead of = on the subquery results. 对于用户来说,拥有多个集合是有意义的,因此您应该调整主查询以在子查询结果上使用IN而不是=。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM