MySQL query, with embedded further query: how?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

MySQL query, with embedded further query: how?

Post by simonmlewis »

Code: Select all

$result = mysql_query ("SELECT * FROM products WHERE userid = '$cookieid' AND method = '123' AND status != 'sold' OR accepted IS NULL AND deleted is NULL");
I need to view all products for the logged in user, only where the method is "123" but within that, only where status is NOT sold, OR.... where accepted IS NULL.... as well as not being deleted.

If this makes sense, please help, as I am getting
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
which I assume is from my $result query.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: MySQL query, with embedded further query: how?

Post by aravona »

Post where ur using mysql_num_rows() ?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: MySQL query, with embedded further query: how?

Post by simonmlewis »

It's ok - I found it.

Code: Select all

$result = mysql_query ("SELECT * FROM products WHERE userid = '$cookieid' AND method = '123' AND (status != 'sold' OR accepted IS NULL) AND deleted is NULL");
This works perfect.

Thanks anyway. Not sure what you meant.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: MySQL query, with embedded further query: how?

Post by aravona »

Ahh ok - its just you posted an error for one thing and didn't show the line with the mysql_num_rows in lol my habit of liking to view everything I guess ^_^
Post Reply