Page 1 of 1

php/mysql - want to select all NOT NULL, not work right..

Posted: Fri Aug 12, 2005 5:52 pm
by camarosource
Trying to do the following:

Select fields "user_from, username, user_email FROM database phpusers where user_from does NOT contain "USA" nor are BLANK, and then order by username.

My PHP script is :

$sql = "SELECT user_from, username, user_email FROM phpbb_users WHERE user_from NOT LIKE '%usa%' OR user_from=NULL OR user_from='' ORDER BY username";

//Execute SQL query
$sql_result = mysql_query($sql,$conn) or die(mysql_error());


It seems to be selecting all those without "USA" which is what I want, however seems to be ignoring the part about NOT wanting to select those that are BLANK (NULL).

Help. Thanks

Posted: Fri Aug 12, 2005 6:14 pm
by PrObLeM

Code: Select all

SELECT * FROM phpbb_users WHERE user_from != 'usa' OR user_from != NULL OR user_from != '' ORDER BY username

that should work

Posted: Fri Aug 12, 2005 6:19 pm
by camarosource
Changed it to :

$sql = "SELECT * FROM phpbb_users WHERE user_from != 'usa' OR user_from != NULL OR user_from != '' ORDER BY username";

//Execute SQL query
$sql_result = mysql_query($sql,$conn) or die(mysql_error());


But it displays if user_from is blank still..

Posted: Fri Aug 12, 2005 6:30 pm
by andre_c
instead of doing

Code: Select all

!= NULL
do

Code: Select all

IS NOT NULL