aeonfox Posted May 2, 2011 Share Posted May 2, 2011 Hi I'm trying to work why the following paramter doesnt work properly. it seems to be ignoring the 'and' part of the query i am using a mysql 5.1.41 server $stmt = $mysqli ->prepare("select CandidateVotes,CandidateTitle, CandidatefirstName ,CandidateLastName,CandidateID from Candidate where ( CandidateFirstName like ? and CandidateLastName like ?) order by CandidateVotes DESC LIMIT 0,?"); $stmt->bind_param('sss', $code1,$code2,$noVotes); $code1="%".$searchFirstName."%"; $code2="%".$searchLastName."%"; $stmt->execute(); $stmt->bind_result($candidateVotes,$candidateTitle,$candidateFirstName,$candidateLastName,$candidateID); Quote Link to comment https://forums.phpfreaks.com/topic/235348-like-operator-problem/ Share on other sites More sharing options...
Psycho Posted May 2, 2011 Share Posted May 2, 2011 What, exactly, do you mean by "it seems to be ignoring the 'and' part of the query". Is the query returning ALL records where the first name is a match regardless of whether the last name matches or not? OR, is it returning results where the first name matches or the last name matches? However I suspect your problem is due to a type $stmt = $mysqli ->prepare("select CandidateVotes,CandidateTitle, CandidatefirstName ,CandidateLastName,CandidateID from Candidate where ( CandidateFirstName like ? and CandidateLastName like ?) order by CandidateVotes DESC LIMIT 0,?"); Quote Link to comment https://forums.phpfreaks.com/topic/235348-like-operator-problem/#findComment-1209488 Share on other sites More sharing options...
aeonfox Posted May 7, 2011 Author Share Posted May 7, 2011 Hi This syntax error did not seem to affect the search results. I still have the same problem. The query does not take into account the second term , the Candidatelastname, and returns the list based only on the first term Cheers Craig Quote Link to comment https://forums.phpfreaks.com/topic/235348-like-operator-problem/#findComment-1211752 Share on other sites More sharing options...
xyph Posted May 7, 2011 Share Posted May 7, 2011 Try using RLIKE instead Quote Link to comment https://forums.phpfreaks.com/topic/235348-like-operator-problem/#findComment-1211764 Share on other sites More sharing options...
aeonfox Posted May 7, 2011 Author Share Posted May 7, 2011 Thanks, that doesn't seem to fix the problem I am getting a result based only on the first term, not one seems to use both search terms. Cheers Craig Quote Link to comment https://forums.phpfreaks.com/topic/235348-like-operator-problem/#findComment-1211767 Share on other sites More sharing options...
Drummin Posted May 7, 2011 Share Posted May 7, 2011 I believe you should quote any text other wise it is treating the "blankand" as part of the WHERE statement. CAPS is also a good idea. Hey maybe I'm wrong but that's what I've found. CandidateFirstName LIKE "?" and CandidateLastName LIKE "?" Quote Link to comment https://forums.phpfreaks.com/topic/235348-like-operator-problem/#findComment-1211769 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.