I have been asked if I can build a search for when the user doesn't know their full name or exact spelling of their name.
This is part of a larger search. The section where I just search for staff with their surname and forename works. Most of the resolutions are using different syntax to mine and as I'm relatively new to coding I'm finding it difficult to read and understand.
Here is my code:
}elseif ($name == '' && $surname == '' && $part !== ''){
$firstName = $part;
$surName = $part;
$query='SELECTt1.staffNum,t1.firstName,t1.surname,t1.jobTitle,t1.hospSite,t1.dept,t1.phone,t1.email,t1.assigned,t1.reason,t1.accessLevel,t1.leaver,t3.course_date,t3.trainingModules
FROM staff_tbl t1
INNER JOIN evaluation_tbl t2
ON t1.staffNum=t2.staffNum
INNER JOIN trainingcourse_tbl t3
ON t2.course_id = t3.course_id
WHERE t1.firstName LIKE : firstName
OR t1.surname LIKE : surName
ORDER BY t1.staffNum';
$firstName = '%$firstName%';
$surName = '%$surName%';
$myStatement= $mydb->prepare($query);
$myStatement->bindValue(':firstName',$firstName);
$myStatement->bindValue(':surName',$surName);
$myStatement->execute();
$results = $myStatement->fetchAll();
$myStatement->closeCursor();
Return $results;
I am entering 'ary' on the front end and should get any staff with that in their name ie Mary Bury but I just get 'no results found'. If I run this query modified in phpMyAdmin SQL it works