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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:05:25+00:00 2026-05-26T16:05:25+00:00

In my database i have one column for first name and last name. In

  • 0

In my database i have one column for first name and last name.
In my code i have combined this two columns and used it as full name.
i have one search box in the display which looks like this,

enter image description here

the code for the searching is like,

switch($search_by){

    case "fullname":
        $sql_where_clause = "fname like '".$search_keyword."%';
        break;
    case "user_name":
        $sql_where_clause = "uname like '".$search_keyword."%';
        break;
    }

and this $sql_where_clause is used in the query for searching.

when i search for full name as arpi which is my first name in database it gives me perfect answer because i have done code for first name.
but the problem is, when i search as arpi patel where arpi is first name and patel is last name then search is not performed because i have not done code for that because i don’t know how to perform this.

does anyone know how to fire query for my first and last name columns together in the $sql_where_clause

  • 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-26T16:05:25+00:00Added an answer on May 26, 2026 at 4:05 pm

    You need to use logical operatores in your SQL query like this:
    $sql_where_clause = "fname LIKE '$fname' AND uname LIKE '$uname'";

    How can you get $fname and $uname variables? If your $search_keyword looks like this:
    family name you can explode it by space $search_parts = explode(' ', $search_keyword, 2). But in that case you do not know which part is the family and which is the name, so you have to perform query like that:
    $sql_where_clause = "(fname LIKE '${part[0]}' AND uname LIKE '${part[1]}') OR (fname LIKE '${part[1]}' AND uname LIKE '${part[0]}')";

    Btw, don’t forget to sanitize your queries against sql-injections. Bad way – use mysql_real_escape_string. Good and easy way – use PDO and prepaired queries.

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

Sidebar

Related Questions

I have two tables in my database. The first one, [nodeActivity] has the following
i have a large mysql database table in which one column contains values ranging
I have the following column specified in a database: decimal(5,2) How does one interpret
In my database, in one of the table I have a GUID column with
I have one database table which contains 8 columns. One of the columns is
i have one database, and it contains some columns. My requirement is that how
In my database, I have a few columns in one of my tables that
I have a SQL Mobile database with one table. It has several columns with
This SELECT finds Kelly as expected: select [First Name], [Last Name], Phone from [Data$]
I have these two entities. One for Employees: [Table(Name = Employees)] public class Employee

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.