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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:50:41+00:00 2026-06-02T10:50:41+00:00

hello i have a select query that is integrated in a search function: i

  • 0

hello i have a select query that is integrated in a search function: i have this code:

foreach ($keywords as $key=>$keyword){
$where .= "`column_a` LIKE '%$keyword%'";
$where .= " OR ";
$where .= "`column_b` LIKE '%$keyword%'";
$where .= " OR ";   
$where .= "`column_c` LIKE '%$keyword%'";
$where .= " OR ";
$where .= "`column_d` LIKE '%$keyword%'";
$where .= " OR ";
$where .= "`column_e` LIKE '%$keyword%'";

    if ($key != ($total_keywords - 1)){ 
        $where .= " AND ";
    }
}

$results = "SELECT `column_a`, `column_b`, `column_c`, `column_d`, `column_e` FROM `table` WHERE $where";

okay, in case of searching for just one keyword the query looks like:

SELECT `column_a`, `column_b`, `column_c`, `column_d`, `column_e` FROM `table` WHERE `column_a` LIKE '%one%' OR `column_b` LIKE '%one%' OR `column_c` LIKE '%one%' OR `column_d` LIKE '%one%' OR `column_e` LIKE '%one%'

what is pretty long. now in case of having two searchterms it will look like:

SELECT `column_a`, `column_b`, `column_c`, column_d`, `column_e` FROM `table` WHERE `column_a` LIKE '%one%' OR `column_b` LIKE '%one%' OR `column_c` LIKE '%one%' OR `column_d` LIKE '%one%' OR `column_e` LIKE '%one%' AND `column_a` LIKE '%two%' OR `column_b` LIKE '%two%' OR `column_c` LIKE '%two%' OR `column_d` LIKE '%two%' OR `column_e` `LIKE` '%two%'

what is definetly too long. so my question is, is there another way to get the same result? i already know that there is MATCH() AGAINST() but this hasnt worked for a unknown reason.

so if there is someone who could help me, i would really appreciate. thanks a lot.

  • 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-06-02T10:50:48+00:00Added an answer on June 2, 2026 at 10:50 am

    Check out this answer.

    It will shorten your query, up to 5 conditions will always be enough.

    More than that, you can join all columns to one and search in it:

    SELECT `column_a`, `column_b`, `column_c`, column_d`, `column_e` FROM `table` 
    WHERE CONCAT(column_a, column_b, column_c, column_d, column_e) REGEXP 'one|two'
    

    But full-text indexes (if you have them) possibly may not work in this query. Check if performance is appropriate.

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

Sidebar

Related Questions

Hello i have this foreach loop that gives weird result , it displays only
hello i have a search function in that i will search a db for
I have a query that looks like this: SELECT id, description, default_error, custom_error FROM
Hello I have this query... if (isset($_REQUEST['deletePost'])) { $q = $dbc -> prepare(DELETE FROM
Hello I have the code below that for some reason is not working: I
Hello this is my query. I want to show the titles of posts that
Hello everyone i have big query to calculation and counter by clinic ID SELECT
Hello I have a table on which I have denied SELECT privs to a
I have the following simple select statement : select 'hello' || '|' || 'world'
I have a dropdown outside the iframe <select id=ModuleDropDown> <option>Hello world</option> </select> and I

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.