So i have this PM system.
At the recipient field, You can type in the full name of who you want to write to.
So I want to help the user alittle, if he don’t remember the name.
So if you want to write the full name “Megan Fox” and only know:
Megan
Megan F
Megan Fo
Meg Fo
M Fox
etc..
It will return “Did you mean Megan Fox?” This already works fine.
Now what I need In this is that if you write only Fox , with no firstname, i want it to echo “Did you mean Megan Fox?”
Here’s where Im stuck, as it creates $lastname after the space. And i really don’t want to use two fields for first and last.
How can I do that?
Here’s my code:
list($firstname, $lastname) = array_map('ucfirst', explode(' ', $mot, 2));
$qur = mysql_query("
SELECT id, firstname, lastname,
(firstname = '$firstname' AND lastname = '$lastname') AS full FROM users
WHERE (firstname = '$firstname' AND lastname='$lastname')
OR (firstname LIKE '$firstname%' AND lastname LIKE '$lastname%')
ORDER BY (firstname = '$firstname' AND lastname='$lastname') DESC");
$get = mysql_fetch_array($qur);
if($get["full"] == 1){
echo $get["id"];
}else{
echo "Did you mean: ".$get["firstname"]." ".$get["lastname"]." ?";
}
This should work.