PHP: If no first name
<p>So i have this PM system.</p>

<p>At the recipient field, You can type in the full name of who you want to write to.</p>

<p>So I want to help the user alittle, if he don't remember the name.</p>

<p>So if you want to write the full name "Megan Fox" and only know:</p>

<pre><code>Megan
Megan F
Megan Fo
Meg Fo
M Fox
etc..
</code></pre>

<p>It will return "Did you mean Megan Fox?" <strong>This already works fine.</strong></p>

<p><em>Now</em> 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?"</p>

<p>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.</p>

<p>How can I do that?</p>

<p>Here's my code:</p>

<pre><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"]." ?";
 }
</code></pre>
