Ryan Beaulieu
Ryan Beaulieu

Reputation: 453

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;

?>

Upvotes: 0

Views: 85

Answers (1)

daemonofchaos
daemonofchaos

Reputation: 795

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.

Upvotes: 2

Related Questions