0

The query below returns this error:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in xxx.php on line 21. Fatal error: Call to a member function fetch_assoc() on boolean in xxx.php on line 24

The query only seems to work when I remove the 'userID' column from both SELECT statements. Does this have anything to do with the fact that i'm using 'userID' for my INNER JOIN? How can I fix this issue? Thanks in Advance.

QUERY;

$sql = "SELECT parentID, userID, Rating, Comment, upvote_count, Time FROM     ratings_n_comments
        INNER JOIN user_details
        ON ratings_n_comments.userID=user_details.UserID 
        WHERE ratings_n_comments.mID= '".$mID."'    
        UNION
        SELECT parentID, userID, Rating, Comment, upvote_count, Time FROM replys_to_comments
        INNER JOIN user_details
        ON replys_to_comments.userID=user_details.UserID 
        WHERE replys_to_comments.mID= '".$mID."'";
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
chiboz
  • 73
  • 8

1 Answers1

0

Table user_details and ratings_n_comments have same column name userID, because of ambiguity it will not display the result. so, use user_details.userID or ratings_n_comments.userID in select statement like i am using below

"SELECT parentID, user_details.userID, Rating, Comment, upvote_count, Time FROM     ratings_n_comments
        INNER JOIN user_details
        ON ratings_n_comments.userID=user_details.UserID 
        WHERE ratings_n_comments.mID= '".$mID."'    
        UNION
        SELECT parentID, user_details.userID, Rating, Comment, upvote_count, Time FROM replys_to_comments
        INNER JOIN user_details
        ON replys_to_comments.userID=user_details.UserID 
        WHERE replys_to_comments.mID= '".$mID."'";
AssenKhan
  • 576
  • 5
  • 15