Jump to content

like operator problem


aeonfox

Recommended Posts

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);

Link to comment
Share on other sites

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,?");
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 "?"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.