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

  • Home
  • SEARCH
  • 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 5964299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:24:23+00:00 2026-05-22T19:24:23+00:00

I am building a user search and I have a Users table with id,

  • 0

I am building a user search and I have a Users table with id, first, and last in it.

I then query a names, say: “John Smith”.

Using PHP I’ll break the query into 2 parts: q1 = John and q2 = Smith.

I want to devise a points system where the record that has first = John and last = Smith gets pulled to the top.

So my sql is something like this:

 SELECT User.id, User.first, User.last
 FROM users as User
 WHERE (User.first = q1 OR User.first = q2) OR //if this is true +1 points
 WHERE (User.last = q1 OR User.last = q2) OR //if this is true +1 points

//then sum up the points and order by it (so the User.id with John Smith will have 2 points)

Any suggestions?

  • 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-22T19:24:25+00:00Added an answer on May 22, 2026 at 7:24 pm

    If your DBMS has an IF function you can do:

    SELECT User.id, User.first, User.last,
        IF (User.first = q1 OR User.first = q2, 1, 0) +
        IF (User.last = q1 OR User.last = q2, 1, 0) as points
    FROM users as User
    ORDER BY points DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so let's say i'm building this contact management system. There is a USER table
I'm building a prototype search application using CakePHP and I have a search controller
I have a form where user can select search criteria. The criterias are say:
I am building my first user control and I would like to package the
I'm building tables using jqGrid with a filter toolbar to let users filter the
I am building an online hotel booking system.... Using php and mysql.... Users can
I'm building an app where the user may occasionally make a search. I'd like
I am building my first PHP/MySQL site and i would like to return search
I'm building an advanced search form for my ASP.NET MVC app. I have a
I am building a code which displays user information on search. User information, is

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.