Rommeo Posted February 21, 2010 Share Posted February 21, 2010 my tables looks like this : advertisement id | topic 7 | hello favorites id | adsid | user id 1 | 7 | 5 I m trying to list the favorites of one user. and I m using this query for to do this : $select_query="SELECT * FROM advertisement WHERE id IN( SELECT adsid FROM favorites where userid = $userid ) "; $result=mysql_query($select_query) || die ( mysql_error()); $total = mysql_num_rows($result); but it gives me this error : Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in file.php on line 61 it was working when there is only one data in the favorites table and the query was like this : ( there is equal sign instead of IN ) $select_query="SELECT * FROM advertisement WHERE id =( SELECT adsid FROM favorites where userid = $userid ) "; What's wrong with my query ? can anyone help? Thanx id advance. Link to comment https://forums.phpfreaks.com/topic/192786-whats-wrong-with-my-query/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 21, 2010 Share Posted February 21, 2010 If you change the || die ( mysql_error()); to or die ( mysql_error()); then the die() statement will be evaluated and output the mysql_error() message that will point out the problem. Using || does not work because the || has lower precedence than the = assignment operator. Link to comment https://forums.phpfreaks.com/topic/192786-whats-wrong-with-my-query/#findComment-1015506 Share on other sites More sharing options...
Rommeo Posted February 21, 2010 Author Share Posted February 21, 2010 Thank you so much PFMaBiSmAd Now it works without any problem when I changed it to "or". Link to comment https://forums.phpfreaks.com/topic/192786-whats-wrong-with-my-query/#findComment-1015508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.