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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:17:46+00:00 2026-05-11T00:17:46+00:00

I’m working on an ‘advanced search’ page on a site where you would enter

  • 0

I’m working on an ‘advanced search’ page on a site where you would enter a keyword such as ‘I like apples’ and it can search the database using the following options:

Find : With all the words, With the exact phrase , With at least one of the words, Without the words

I can take care of the ‘Exact phrase’ by:

SELECT * FROM myTable WHERE field='$keyword'; 

‘At least one of the words’ by:

SELECT * FROM myTable WHERE field LIKE '%$keyword%';//Let me know if this is the wrong approach 

But its the ‘With at least one of the words’ and ‘Without the words’ that I’m stuck on.

Any suggestions on how to implement these two?

Edit: Regarding ‘At least one word’ it wouldn’t be a good approach to use explode() to break the keywords into words, and run a loop to add

(field='$keywords') OR ($field='$keywords) (OR).... 

Because there are some other AND/OR clauses in the query also and I’m not aware of the maximum number of clauses there can be.

  • 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. 2026-05-11T00:17:47+00:00Added an answer on May 11, 2026 at 12:17 am

    I would suggest the use of MySQL FullText Search using this with the Boolean Full-Text Searches functionality you should be able to get your desired result.

    Edit:

    Requested example based on your requested conditions (‘Its just one field and they can pick either of the 4 options (i.e 1 word, exact words, at least 1 word, without the term).’)

    I am assuming you are using php based on your initial post

    <?php $choice = $_POST['choice']; $query = $_POST['query'];  if ($choice == 'oneWord') {     //Not 100% sure what you mean by one word but this is the simplest form     //This assumes $query = a single word     $result = mysql_query('SELECT * FROM table WHERE MATCH (field) AGAINST ('{$query}' IN BOOLEAN MODE)'); } elseif ($choice == 'exactWords') {     $result = mysql_query('SELECT * FROM table WHERE MATCH (field) AGAINST ('\'{$query}\'' IN BOOLEAN MODE)'); } elseif ($choice == 'atLeastOneWord') {     //The default with no operators if given multiple words will return rows that contains at least one of the words     $result = mysql_query('SELECT * FROM table WHERE MATCH (field) AGAINST ('{$query}' IN BOOLEAN MODE)'); } elseif ($choice == 'withoutTheTerm') {     $result = mysql_query('SELECT * FROM table WHERE MATCH (field) AGAINST ('-{$query}' IN BOOLEAN MODE)'); } ?> 

    hope this helps for full use of the operators in boolean matches see Boolean Full-Text Searches

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

Sidebar

Related Questions

I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I would like to run a str_replace or preg_replace which looks for certain words
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.