Showing more than two name & space issue
<p>I am making an PM system for my users.</p>

<p>In the recipient field you type in a full name. When you submit i want to make sure it's the right user he sends to.</p>

<p>So if he type "Megan Fox", it's a full match of a user. But if he type Meg F or Megan, Fox it will return "Did you mean Megan Fox?"</p>

<p>So...</p>

<p>Now I have thought what if there's more than one with the name "Megan" or the lastname "Fox". I made a while() for that, and it will return if theres more than 1, "Who did you mean: Matt Fox, Megan Fox?"</p>

<p>Now I havnt found where It goes wrong, I got 3 rows with the lastname "Fox", it only shows two of them in the "Who did you mean?"</p>

<p>How can I solve this?</p>

<p>And if I only enter a space in the recipient field, it will return all users, in the table. How can i prevent this?</p>

<p>Here's what my code looks like:</p>

<pre><code>$mot = mysql_real_escape_string($_POST['mottagare']);
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%')
 OR firstname LIKE '$firstname%' OR lastname LIKE '$firstname%'
 ORDER BY (firstname = '$firstname' AND lastname='$lastname') DESC");

 $get = mysql_fetch_array($qur);

 if(mysql_num_rows($qur) == 1){
    if($get["full"] == 1){
    echo $get["id"];
    }else{
     echo "Did you mean ".$get["firstname"]." ".$get["lastname"]." ?";
    }
 }elseif(mysql_num_rows($qur) &gt; 1){
    while($get = mysql_fetch_array($qur)) {
       $name[] = $get["firstname"]." ".$get["lastname"];
   }

   if(count($name) &gt; 1) {
       echo 'Who did you mean?&lt;br&gt;';
   } else {
       echo 'Did you mean: ';
   }
   echo implode('&lt;br&gt;', $name);

 }
</code></pre>
