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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:03:38+00:00 2026-05-28T08:03:38+00:00

I have a search form field that I want to compare with multiple columns

  • 0

I have a search form field that I want to compare with multiple columns within a table e.g.:

+----------+-------+---------+------+------------+
| name     | owner | species | sex  | birth      |
+----------+-------+---------+------+------------+
| Claws    | Gwen  | cat     | m    | 1994-03-17 |
| Bowser   | Diane | dog     | m    | 1989-08-31 |
| Whistler | Gwen  | cat     | m    | 1997-12-09 |
+----------+-------+---------+------+------------+

The query I made has multiple LIKE comparisons however it only seems to find rows of data for the first two columns.

The first comparison is “name” then “owner” then “species” then “sex“.

It only finds rows if you enter a string that matches the first two columns, however if you enter a string that matches one of the last columns it does not return anything.

Here is the query:

SELECT * FROM contact 
WHERE name LIKE \"%$search%\" 
OR owner LIKE \"%$search%\"
OR species LIKE \"%$search%\" 
OR sex LIKE \"%$search%\" 
GROUP BY name, owner,species, sex

My only guess is that MySQL perhaps limits how many “OR“s you can use?

My query should return a row from the table if the string entered by the user matches any column data.

Here is my PHP code for it

include("database.class.php");

    //search string assigned from POST field
    $search = $_POST['contact_search'];

    $db = new database();

    $db->select('quote_system');

    $result = $db->query("SELECT * FROM contact WHERE name LIKE \"%$search%\" OR owner LIKE \"%$search%\" OR species LIKE \"%$search%\" OR sex LIKE \"%$search%\" GROUP BY name, second_name, owner, species, sex");

    print_r($result);

    while ($row = $db->fetch_assoc($result))
    {
        echo $row['name'];
        echo $row['owner'];
        echo $row['species'];
        echo $row['sex'];
        echo "<br/>";

    }

Incase theres any confusion here are some examples to show the problem:

User enters string “claws” –> string matches data in “name” column –> prints row that column is in

User enters string “m” –> string only matches data in “sex” column –> nothing shows!

Thanks for your time!

  • 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-28T08:03:39+00:00Added an answer on May 28, 2026 at 8:03 am

    Your query

    $result = $db->query("
      SELECT * FROM contact 
      WHERE first_name LIKE \"%$search%\" 
      OR second_name LIKE \"%$search%\" 
      OR company_name LIKE \"%$search%\" 
      OR email LIKE \"%$search%\" 
      GROUP BY first_name, second_name, company_name, email
    ");
    

    seems to belong to another table. Also, why do you GROUP BY? Maybe, you meant ORDER BY?

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

Sidebar

Related Questions

I'm creating a form with a single search field and I want that field
I want to create a really simple search form, basically a single field, that
(Using MySQL and PHP) I have a search form that will allow my users
I want to have a text value for a form like search website.com... but
If I have a GET search field, how could I have that submit to
I have a a form that I want to output as custom HTML. My
Preface I have a need to create multiple copies of a search form (in
I have a search form with min and max fields. It queries a MySQL
I have a search form with a query builder. The builder is activated by
I have a search form in an app I'm currently developing, and I would

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.