Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
Thread: problem with select where
02-23-2014, 04:45 AM #1
problem with select where
Any idea why my query is returning the article where priority is set to zero
when query is to select articles with priority greater than zero?
Without the AND clause it works, but I need the AND clause so I can't remove it.
myDatabase setting for 'priority' col
smallint(11) //values possible from form 0-9
test field values in database:
News test test 0
myQuery in php page:
$result = $mysqli->query("SELECT `headline`,`title`,`article`,`priority`
WHERE (`priority` > 0)
AND (`title` IS NOT NULL) OR (`article` IS NOT NULL)
Priority: 0 <--this article should not be selected
I also tried WHERE (priority >= 1)
which also didn't work
02-23-2014, 05:00 AM #2
- Join Date
- Oct 2006
- Denver, Colorado USA
- Thanked 373 Times in 365 Posts
The query is matching everything with (`article` IS NOT NULL) being true. or'ing values will return a true if one or both of the values is true - false OR true = true.
use this logic -
Code:WHERE (`priority` > 0) AND ((`title` IS NOT NULL) OR (`article` IS NOT NULL))
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
Users who have thanked CFMaBiSmAd for this post:
low tech (02-25-2014)
02-24-2014, 01:13 AM #3
Ah that looks good. I'll give that a try and post back.
I'd add a 'thanks' , but I can't see where to add that on the new forum.
Last edited by low tech; 02-24-2014 at 01:29 AM.
02-24-2014, 01:58 AM #4
EDIT: Found and clicked THANKS
Your code did the trick nicely.
Thanks and thanks for the explanation.
Last edited by low tech; 02-25-2014 at 05:12 AM.