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 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'm doing this system Stacked and I am creating the search function. And in
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
I'm creating a stored procedure to return search results where some of the parameters
While creating a file synchronization program in C# I tried to make a method
.NET 3.5, C# I have a web app with a search feature. Some of
I'm working on a feature to export search results to a CSV file to
I'm creating a bulletin board system, and now I'm implementing a 'delete topic' feature
I'm working on a search feature in one of my Core Data based apps
Im working with a developer in creating a iphone search bar in an applications

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.