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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:20:56+00:00 2026-05-31T03:20:56+00:00

I am working with PHP and MySQL. I’ll provide a simple table below: ——————————————————

  • 0

I am working with PHP and MySQL. I’ll provide a simple table below:

------------------------------------------------------
|  id |                    text                      |
------------------------------------------------------
|  1  | The quick brown fox jumped over the lazy dog | 
------------------------------------------------------

I’d like users to be able to search using keywords separated by spaces. I’ve got a simple SQL query for the above which is SELECT * FROM table WHERE text LIKE %[$keyword]% which means if I search for “The quick fox”, I won’t get any results. Is there a way to separate the keywords by spaces so if I search for “The quick fox”, it will run 3 searches. One for “The”, one for “quick”, and one for “fox” – removing all white spaces. Though it should only display one result since it all belongs to the same row instead of 3 since all 3 keywords matched the data in the row.

What’s the best way to do this? All suggestions to do this better are always welcome. Thanks!

[EDIT]

Just thought of this now, would separating the keywords by comma (,) be a better option?

  • 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-31T03:20:57+00:00Added an answer on May 31, 2026 at 3:20 am

    You might consider a regular expression via REGEXP to separate the words into an or group.

    SELECT * 
    FROM tbl
    WHERE
      LOWER(`text`) REGEXP '\b(the|quick|fox)\b'
    

    Matches:

    • The quick brown fox jumps over the lazy dog
    • Quick, get the fox!
    • I ate the cake

    Doesn’t match

    • Brown dogs

    Inside PHP, you can construct this expression by splitting your search string on the spaces and imploding it back on | after escaping each component.

    $str = "the quick brown fox";
    $kwds = explode(" ", $str);
    $kwds = array_map("mysql_real_escape_string", $kwds);
    $regexp = "\b(" . implode("|", $kwds) . ")\b";
    

    Then use REGEXP '$regexp' in your statement.

    Addendum:

    Since you didn’t mention it in the OP, I want to be sure you aware of MySQL’s full text searching capabilities on MyISAM tables, in case it can meet your need. From your description, full text doesn’t sound like exactly your requirement, but you should review it as a possibility: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

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

Sidebar

Related Questions

I am working in PHP/MySQL. I have a table in my database called hourly
I am working on an inventory php/mysql application. I have a main table (inv_main)
I am working on a large php/mysql application, and I am getting to the
I am currently working on a small sponsorship application(PHP/MySql) for my personal blog, and
Im working on a website (html,css,javascript, ajax, php,mysql), and I want to restrict the
I am working on an issue management system, developed in PHP/MySQL. It requires search
I am currently working on a web application that uses PHP and MySQL, but
I am working on a personal project based in PHP and MySQL, and I
I'm a real newbie with php and MySQL. Now I'm working on the following
I am using MySQL and PHP for a project I am working. I have

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.