Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3337976
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:19:07+00:00 2026-05-18T00:19:07+00:00

I am making an PM system for my users. In the recipient field you

  • 0

I am making an PM system for my users.

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.

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?”

So…

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?”

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?”

How can I solve this?

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

Here’s what my code looks like:

$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) > 1){
    while($get = mysql_fetch_array($qur)) {
       $name[] = $get["firstname"]." ".$get["lastname"];
   }

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

 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:19:08+00:00Added an answer on May 18, 2026 at 12:19 am

    In this line:

    $get = mysql_fetch_array($qur);
    

    you already fetched the first of your names without appending it to the $name array, so in this line:

    while($get = mysql_fetch_array($qur)) {
    

    the first one will not be fetched from the DB again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been making a threaded comment system as a way to learn php
We are making a lab instrument using an ARM9/RTOS system. The client has asked
For some school groupwork, I'm making a Generic Pizza Delivery Everything Management System, and
After making some changes in my models (eg. new field in a model and
Exception Thrown: System.ComponentModel.ReflectPropertyDescriptor is not marked as Serializable Does this mean I missed marking
Making echo of a question around the web: Is the syntax for svn:ignore patterns
When making changes using SubmitChanges() , LINQ sometimes dies with a ChangeConflictException exception with
After making a few modifications to a rails app I am tinkering on, railroad
Im making a small python script to upload files on the net. The script
I've been making a concerted effort to improve my javascript skills lately by reading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.