简体   繁体   中英

Mysql Nested Query Trouble

I have created a mysql seect statement with a nested select statement. Now my mysql skills (or lack there of) are very limited. Below is the code that I wrote. I was getting blank results or the Warning. mysql_fetch_Array error. 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. 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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