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 "; 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? 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. 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. 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 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
Archived
This topic is now archived and is closed to further replies.