Jump to content

Struggling with Where Clause !


sohaibshaheen

Recommended Posts

Usually I prefer to search the internet instead of Posting it somewhere! But This time I am stuck ...  :shrug: .... I got no other option when such simple statement isn't giving expected response!

 

To the point.. What I want to do is to get the posts from table "user_post" where

 

1. (postby = current user && postfor=NULL)

2. OR (postfor = Current User)

 

to display on users wall...

 

The code looks like this..

 

mysql_query(" SELECT * FROM user_post WHERE ( (postby='$cur_user_id' && postfor=NULL) || (postfor='$cur_user_id') )  ORDER BY postdate DESC LIMIT $num_posts") 
					or die(mysql_error()); 

 

But all it gives is the postfor= current user

 

Somebody plz take me out of this pit!!!  :confused: 

Link to comment
https://forums.phpfreaks.com/topic/211981-struggling-with-where-clause/
Share on other sites

Nothing is ever equal to NULL, not even another NULL.  You have to use 'IS NULL'

 

mysql_query(" SELECT * FROM user_post 
WHERE ( (postby='$cur_user_id' && postfor IS NULL) || (postfor='$cur_user_id') )  
ORDER BY postdate DESC LIMIT $num_posts")
                  or die(mysql_error()); 

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.