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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:44:02+00:00 2026-05-24T09:44:02+00:00

I am creating a search feature for a products catalog. Here is the input

  • 0

I am creating a search feature for a products catalog.

Here is the input code so far:

<form name="search" method="post" action="'.$PHP_SELF.'">
    <div>
    Search for: <input type="text" name="find" />
    <input type="hidden" name="searching" value="yes" />
    <input type="submit" name="search" value="Search" />
    </div>
</form>

Here is the query that queries the Mysql database for a match:

SELECT * FROM `products` WHERE upper(`desc`) LIKE'%$find%'

This all works perfectly fine, when the user searches for a one word string.

What the problem is here, is that when a user searches for a two word string, no match is found as sometimes these strings relate to seperate features.

An example of this would be, the products catalog contains information about various chocolates:

You get bars of chocolates, boxes of chocolates, packets of chocolates, etc…

Now although some of the descriptions held in the field desc contain the words chocolate and bar, some contain variations, like “company bars 120g chocolates”.

This causes a problem in the above code, because if a user searches “chocolate bar” unless the description in the desc field contains that variation explicitly, no matches will be returned.

What I would like to happen, is when a user searches “chocolate bar” any match containing the varitions “chocolate” and “bar” will be returned.

Does anyone have any input on how i would go about this task?

Possibily turn $find into an array and make ” ” a delimiter?

  • 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-24T09:44:03+00:00Added an answer on May 24, 2026 at 9:44 am

    Maybe you could do something like this:

    $keywords_array = explode(' ', $find);
    
    $qry = "SELECT * FROM `products` WHERE `desc` LIKE '%" 
           . implode("%' OR `desc` LIKE '%", $keywords_array) 
           . "%'";
    

    Output for $find = 'this':

    SELECT * FROM products WHERE desc LIKE ‘%this%’

    Output for $find = 'this and that':

    SELECT * FROM products WHERE desc LIKE ‘%this%’ OR desc LIKE ‘%and%’ OR desc LIKE ‘%that%’

    This sure is a very basic functionality, but you get the idea.

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

Sidebar

Related Questions

I am creating a simple search feature that queries a user input string for
I have been tasked with creating a site wide search feature. The search needs
I'm creating a custom search form and when I try and sort the results
I am creating a search function of my classifieds on my website. Here is
Im using rails 3.1, and I am creating a search form with ajax, I
I tried to search here before creating this, but I couldn't find anything. I
I am creating a search list in java. If I enter the beginning letters,
I am creating a search page where we can find the product by entering
Seems simple enough. I'm creating a search engine that returns results to the user
I'm creating video music search in android WebView and I wanted users can launch

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.