For the recipient field in my message system, if you enter Megan Fo, it will ask you “Did you mean Megan Fox?”. Then I also have a “Who did you mean? Megan Fox, Megan Foxxy, Megan Foxxie” if there’s more than one found.
And then ofcourse there is if you made it correct. (if this SQL statement is returning 1 only out and the full is 1).
SELECT users.id, users.firstname, users.lastname,
(users.firstname = 'Meg' AND users.lastname = 'Meg') AS full FROM users
INNER JOIN users_friends ON users.id=users_friends.uID
WHERE users_friends.bID='1' AND users_friends.type = 'friend' AND users_friends.accepted = '1' AND (
(users.firstname = 'Meg' AND users.lastname='Meg') OR
(users.firstname LIKE 'Meg%' AND users.lastname LIKE 'Meg%') OR
users.firstname LIKE 'Meg%' OR
users.lastname LIKE 'Meg%')
This is working fine, although now I am having an issue when Im trying to send to a user
“Meg Meg”
Then it returns 2, “Meg Meg” and “Megan Fox”. I want it to return one only if it matchs the full. So now I am keep getting “Who did you mean?” as i build it up so if thers more than 1 rowcount, then “who did you mean..”
if($sql_findUser->rowCount() == 1){
$get = $sql_findUser->fetch();
if($get["full"] == 1){
echo "SUCCESS, ONE FOUND FULL MATCH"
}else{
echo "Did you mean ...?"
}
}elseif($sql_findUser->rowCount()>1){
Who did you mean?
}
How can i fix this?
At the end of your SQL statement, it looks like you’re including everyone with a first name starting with “Meg”, which is why Meg Meg and Megan Fox both match. Try shortening your WHERE clause to: