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 3321114
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:01:26+00:00 2026-05-17T23:01:26+00:00

Hey, so I have a recipient field in my form you can type a

  • 0

Hey, so I have a recipient field in my form you can type a user´s fullname in, example “john derek”.

Now i have exploded this into $firstname and $lastname

list($firstname, $lastname) = array_map('ucfirst', explode(' ', $recipient, 2));

How can i check in the database if there’s any full match, take the id.

table users has column “firstname” and “lastname”

If theres half match, if only there exists firstname (john) or lastname(derek) and not both, echo “Did you mean: John Derek?”;

$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);
 echo $get["full"] ."<br>";

Im not getting anything in this, even that $firstname is “John” and $lastname is “Derek”

also tried:

echo $get["id"];
echo $get["lastname"]
echo $get["firstname"]

Seems like it dont find anything? What is wrong?

  • 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-17T23:01:27+00:00Added an answer on May 17, 2026 at 11:01 pm

    The simplest way is to do a LIKE query:

     SELECT id, firstname, lastname FROM users 
     WHERE firstname LIKE "$firstname%"
     AND lastname LIKE "$lastname%"
    

    (Don’t forget sanitizing the variables, of course)

    User input that this would match:

    Jo De
    J Derek
    John D
    

    It would give you a result set back. If, for a search for John Der, there is a John Derek and a John Der though, there’s no guarantee that John Der will come first. To achieve that, you’d have to check for literal matches first:

     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
    

    this will give the full match first, partial matches second.

    It may need further tweaking, but it should be a start.

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

Sidebar

Related Questions

hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;
Hey I have been battling with this problem for a while now. Perhaps there
Hey I have this configuration in my web.config <log4net> <appender name=LogFileAppender type=log4net.Appender.FileAppender> <param name=File
Hey I have this code right here: http://pastie.org/534470 And on line 109 I get
Hey I have this code but it doesn't work because it is expecting a
Hey I have this kinda structure in my ini file I want to be
Hey all i have two JFrames one is my main login frame, user enters
Hey I have this little javascript bookmark javascript:(function(){ window.open('http://www.mywebsite.com/index.php?currentsite#bookmark'); })() How can I get
hey I have this silly issue and I hope you could help me to
Hey I have a function which is called from a html link like this:

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.