Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would suggest the use of <a href="http://dev.mysql.com/doc/refman/5.1/en/fulltext-search.html" rel="noreferrer">MySQL FullText Search</a> using this with the <a href="http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html" rel="noreferrer">Boolean Full-Text Searches</a> functionality you should be able to get your desired result.</p> <p>Edit:</p> <p>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).")</p> <p>I am assuming you are using php based on your initial post</p> <pre><code>&lt;?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)"); } ?&gt; </code></pre> <p>hope this helps for full use of the operators in boolean matches see <a href="http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html" rel="noreferrer">Boolean Full-Text Searches</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload