MDanz Posted July 15, 2010 Share Posted July 15, 2010 this isn't working out. I want the first part of the if statement to get both results in mysql with adult=1 and 0. i think i did it wrong. Whats the correct way? if($adulton == 1) { $adult="adult=1 AND adult=0"; } else { $adult="adult=0"; } WHERE keywords LIKE '$letter%' AND Amount>=1 AND $adult Quote Link to comment https://forums.phpfreaks.com/topic/207814-help-with-where-clause/ Share on other sites More sharing options...
bh Posted July 15, 2010 Share Posted July 15, 2010 Hi, if($adulton == 1) { $adult="adult=1 AND adult=0"; } Here, adult can be 1 and 0 at the same time. User OR connection. if($adulton == 1) { $adult="adult=1 OR adult=0"; } Quote Link to comment https://forums.phpfreaks.com/topic/207814-help-with-where-clause/#findComment-1086330 Share on other sites More sharing options...
MDanz Posted July 15, 2010 Author Share Posted July 15, 2010 thanks but now the first parts of the where clause are being ignored. Do i have to use brackets around $adult to make it specific.? SELECT DISTINCT keywords FROM Core WHERE keywords LIKE '$letter%' AND Amount>=1 AND $adult ORDER BY keywords DESC" this is getting all rows from mysql where adult='0'.. it is ignoring the keywords LIKE '$letter%' AND Amount>=1 Quote Link to comment https://forums.phpfreaks.com/topic/207814-help-with-where-clause/#findComment-1086331 Share on other sites More sharing options...
bh Posted July 15, 2010 Share Posted July 15, 2010 "SELECT DISTINCT keywords FROM Core WHERE keywords LIKE '$letter%' AND Amount>=1 AND ({$adult}) ORDER BY keywords DESC" Quote Link to comment https://forums.phpfreaks.com/topic/207814-help-with-where-clause/#findComment-1086334 Share on other sites More sharing options...
MDanz Posted July 15, 2010 Author Share Posted July 15, 2010 thanks for help. i have 1 row in mysql where adult=1. the rest are adult=0. When i run the query i want to filter out the adult results. For some reason the query isn't working. when i turnoff the adult filter... it shows both adult=1 and adult=0 rows, when it should only show adult=0 rows. It's a query problem. any idea why? Quote Link to comment https://forums.phpfreaks.com/topic/207814-help-with-where-clause/#findComment-1086342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.