Note that there are some explanatory texts on larger screens.

plurals
  1. POAssign search results into a variable - PHP Fulltext Search Boolean
    primarykey
    data
    text
    <p>I created a Fulltext search in Boolean Mode using PHP/MySQL. It runs perfectly, with relevance ranking and index assigned to concerned database fields. The database contains two tables:</p> <p><em><strong>business</em></strong> -> name, description, contact, address, serialid</p> <p>*<strong>search_terms*</strong> -> terms, querytime, date_searched, results.</p> <p>Then now, <strong>I want to get all the search results and assigned it to a variable</strong> (<strong>$results</strong>). This <strong>$result</strong> will be stored to the search_term table along with terms, querytime and date_searched.</p> <p>Here is my code (without $result)</p> <pre><code>function search($term){ $term = mysql_real_escape_string($term); $startTime = microtime(true); $query = mysql_query("SELECT *, MATCH (Name) AGAINST ('+$term*' IN BOOLEAN MODE) AS rel1, MATCH (Description) AGAINST ('+$term*' IN BOOLEAN MODE) AS rel2, MATCH (Keywords) AGAINST ('+$term*' IN BOOLEAN MODE) AS rel3 FROM business WHERE MATCH (Name,Description,Keywords) AGAINST ('+$term*' IN BOOLEAN MODE) ORDER BY (rel1*0.60)+(rel2*0.25)+(rel3*0.15) DESC") or die(mysql_error()); $endTime = microtime(true); $queryTime = substr($endTime - $startTime, 0,6); if(mysql_num_rows($query) == 0){ echo "&lt;p&gt;No results found for &lt;i&gt;". $term ."&lt;/i&gt;&lt;/p&gt;"; } else{ while($row = mysql_fetch_assoc($query)){ echo "&lt;h4&gt;&lt;a href='viewBusiness.php?serial=" . $row['SerialId'] . "'&gt;" . $row['Name'] . "&lt;/a&gt;&lt;/h4&gt;"; $desc = substr($row['Description'], 0,100); $score = $row['rel1'] + $row['rel2'] + $row['rel3']; echo "&lt;p&gt;" . $desc .". . .&lt;/p&gt;"; } $numOfResult = mysql_num_rows($query); echo "&lt;hr/&gt;&lt;p&gt;&lt;b&gt;" . $numOfResult ." &lt;/b&gt;result(s) found within " . $queryTime . " seconds.&lt;/p&gt;"; $ip = $_SERVER['REMOTE_ADDR']; $query2 = mysql_query("INSERT INTO search_term(Term, QueryTime, Ip) VALUES('$term', '$queryTime', '$ip')") or die(mysql_error()); } } </code></pre> <p>I am novice in PHP and this is my first application. Thank you very much for the help!</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. 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