Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.