thminco Posted May 31, 2011 Share Posted May 31, 2011 I'm trying to do an sql query from php that includes 15 condition "groups" each consisting of 4 conditions. I have tried separating each condition group with brackets but still can't get it to work. Am I missing something? Thanks as always for everyone's help!! Tom Here is the code shown with line breaks for clarity: $query="SELECT * FROM d4dauctions WHERE (`user gender` LIKE '%$gender%' AND `auction area` LIKE '%$auctionarea%' AND `user age group` LIKE '%$agegroup%' AND `type of bid` LIKE '%$typeofbid%') OR ('$usergender' = 'Either' AND `auction area` LIKE '%$auctionarea%' AND `user age group` LIKE '%$agegroup%' AND `type of bid` LIKE '%$typeofbid%') OR ('$auctionarea' = 'Anywhere' AND `user gender` LIKE '%$gender%' AND `user age group` LIKE '%$agegroup%' AND `type of bid` LIKE '%$typeofbid%') OR ('$agegroup' = 'Any age' AND `user gender` LIKE '%$gender%' AND `auction area` LIKE '%$auctionarea%' AND `type of bid` LIKE '%$typeofbid%') OR ('$typeofbid' = 'Any type of bid' AND `user gender` LIKE '%$gender%' AND `auction area` LIKE '%$auctionarea%' AND `user age group` LIKE '%$agegroup%') OR ('$usergender' = 'Either' AND '$auctionarea' = 'Anywhere' AND `user age group` LIKE '%$agegroup%' AND `type of bid` LIKE '%$typeofbid%') OR ('$usergender' = 'Either' AND `auction area` LIKE '%$auctionarea%' AND '$agegroup' = 'Any age' AND `type of bid` LIKE '%$typeofbid%') OR ('$usergender' = 'Either' AND `auction area` LIKE '%$auctionarea%' AND `user age group` LIKE '%$agegroup%' AND '$typeofbid' = 'Any type of bid') OR (`user gender` LIKE '%$gender%' AND '$auctionarea' = 'Anywhere' AND '$agegroup' = 'Any age' AND `type of bid` LIKE '%$typeofbid%') OR (`user gender` LIKE '%$gender%' AND '$auctionarea' = 'Anywhere' AND `user age group` LIKE '%$agegroup%' AND '$typeofbid' = 'Any type of bid') OR (`user gender` LIKE '%$gender%' AND `auction area` LIKE '%$auctionarea%' AND '$agegroup' = 'Any age' AND '$typeofbid' = 'Any type of bid') OR ('$usergender' = 'Either' AND '$auctionarea' = 'Anywhere' AND '$agegroup' = 'Any age' AND `type of bid` LIKE '%$typeofbid%') OR ('$usergender' = 'Either' AND `auction area` LIKE '%$auctionarea%' AND '$agegroup' = 'Any age' AND '$typeofbid' = 'Any type of bid') OR ('$usergender' = 'Either' AND '$auctionarea' = 'Anywhere' AND `user age group` LIKE '%$agegroup%' AND '$typeofbid' = 'Any type of bid') OR ('$usergender' = 'Either' AND '$auctionarea' = 'Anywhere' AND '$agegroup' = 'Any age' AND '$typeofbid' = 'Any type of bid') ORDER BY RANK DESC "; Quote Link to comment https://forums.phpfreaks.com/topic/237943-is-there-a-limit-to-andor-statements-or-bracketing-in-a-php-sql-query/ Share on other sites More sharing options...
mikesta707 Posted May 31, 2011 Share Posted May 31, 2011 is this code returning a mysql error? what exactly happens when you run this? Quote Link to comment https://forums.phpfreaks.com/topic/237943-is-there-a-limit-to-andor-statements-or-bracketing-in-a-php-sql-query/#findComment-1222694 Share on other sites More sharing options...
thminco Posted May 31, 2011 Author Share Posted May 31, 2011 I don't get any errors but I'm not getting the result set that I should. In fact, I get NO result set even though the database has records that meet the four conditions in a group. Quote Link to comment https://forums.phpfreaks.com/topic/237943-is-there-a-limit-to-andor-statements-or-bracketing-in-a-php-sql-query/#findComment-1222695 Share on other sites More sharing options...
thminco Posted May 31, 2011 Author Share Posted May 31, 2011 BTW...It seemed to work fine when I had just the first four groups, even without the brackets. Quote Link to comment https://forums.phpfreaks.com/topic/237943-is-there-a-limit-to-andor-statements-or-bracketing-in-a-php-sql-query/#findComment-1222697 Share on other sites More sharing options...
thminco Posted May 31, 2011 Author Share Posted May 31, 2011 Sorry guys...I found my problem...a bad variable name! (I know I'm a dork!) I sure appreciate everyone though! Tom Quote Link to comment https://forums.phpfreaks.com/topic/237943-is-there-a-limit-to-andor-statements-or-bracketing-in-a-php-sql-query/#findComment-1222702 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.