Jump to content

what's wrong with my query ?


Rommeo

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.