Note that there are some explanatory texts on larger screens.

plurals
  1. POdisplaying search results of more than one word
    primarykey
    data
    text
    <p>in my search form, if the user types 'good', it displays all the results which contain the keyword 'good'. however if the user types in 'good sweetest', it displays no results because there is no record with the two words appearing together; BUT appearing in an entry at different places. </p> <p>for example, the record says: </p> <blockquote> <p>A good action is an ever-remaining store and a pure yield</p> </blockquote> <p>the user types in 'good', it will show up this record, but if the user types in 'good' + 'pure', it will not show anything. or if the record contains the keyword 'good-deeds' and if the user types in 'good deeds' without the hyphen, it will not show anything.</p> <p>what i would like is that if the user types in 'good' + 'pure' or 'good deeds' it should records containing these keywords highlighting them. </p> <p>search.php code:</p> <pre><code>$search_result = ""; $search_result = $_POST["q"]; $search_result = trim($search_result); //Check if the string is empty if ($search_result == "") { echo "&lt;p class='error'&gt;Search Error. Please Enter Your Search Query.&lt;/p&gt;" ; exit(); } if ($search_result == "%" || $search_result == "_" || $search_result == "+" ) { echo "&lt;p class='error1'&gt;Search Error. Please Enter a Valid Search Query.&lt;/p&gt;" ; exit(); } $result = mysql_query('SELECT cQuotes, vAuthor, cArabic, vReference FROM thquotes WHERE cQuotes LIKE "%' . mysql_real_escape_string($search_result) .'%" ORDER BY idQuotes DESC', $conn) or die ('Error: '.mysql_error()); function h($s) { echo htmlspecialchars($s, ENT_QUOTES); } function highlightWords($string, $word) { $string = preg_replace("/".preg_quote($word, "/")."/i", "&lt;span class='highlight'&gt;$0&lt;/span&gt;", $string); /*** return the highlighted string ***/ return $string; } ?&gt; &lt;div class="caption"&gt;Search Results&lt;/div&gt; &lt;div class="center_div"&gt; &lt;table&gt; &lt;?php while ($row= mysql_fetch_array($result, MYSQL_ASSOC)) { $cQuote = highlightWords(htmlspecialchars($row['cQuotes']), $search_result); ?&gt; &lt;tr&gt; &lt;td style="text-align:right; font-size:18px;"&gt;&lt;?php h($row['cArabic']); ?&gt;&lt;/td&gt; &lt;td style="font-size:16px;"&gt;&lt;?php echo $cQuote; ?&gt;&lt;/td&gt; &lt;td style="font-size:12px;"&gt;&lt;?php h($row['vAuthor']); ?&gt;&lt;/td&gt; &lt;td style="font-size:12px; font-style:italic; text-align:right;"&gt;&lt;?php h($row['vReference']); ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>search.html:</p> <pre><code> &lt;form name="myform" class="wrapper"&gt; &lt;input type="text" name="q" onkeyup="showUser()" class="txt_search"/&gt; &lt;input type="button" name="button" onclick="showUser()" class="button"/&gt; &lt;p&gt; &lt;div id="txtHint"&gt;&lt;/div&gt; &lt;/form&gt; </code></pre>
    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.
 

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