php - How to apply multy word search in mysql -
i need points on how make php script not 1 word or multiple ( john doe ). script find 1st word "john" pointed table. here script:
$query = $_get['query']; $min_length = 1; if (strlen($query) >= $min_length) { $query = htmlspecialchars($query); $query = mysql_real_escape_string($query); $raw_results = mysql_query( "select * filmi (`title` '%".$query."%') or (`description` '%".$query."%') or (`nomer` '%".$query."%')" ) or die(mysql_error()); if (mysql_num_rows($raw_results) > 0) { while ($results = mysql_fetch_array($raw_results)) { echo " print results "; } } else { echo "no results"; } } else { echo "minimum length " . $min_length; }
use code, have added new line.
this added wild cards % in place of space modify existing query , adds wildcard it. way can find records containing words in given search query.
<?php $query = $_get['query']; $min_length = 1; if(strlen($query) >= $min_length){ $query = htmlspecialchars($query); $query = mysql_real_escape_string($query); //added new line ################ $query = str_replace(' ', '%', $query); $raw_results = mysql_query("select * filmi (`title` '%".$query."%') or (`description` '%".$query."%') or (`nomer` '%".$query."%')") or die(mysql_error()); if(mysql_num_rows($raw_results) > 0){ while($results = mysql_fetch_array($raw_results)){ echo " print results "; } } else{ echo "no results"; } } else{ echo "minimum length ".$min_length; } ?>
Comments
Post a Comment