0

i have script and my search term is new york it show me the me result. if i search for new yor it contain no result. here is my php code.

$query="SELECT * FROM states 
        WHERE MATCH(title,url,description) 
                AGAINST('".$search."' IN NATURAL LANGUAGE MODE)
        ORDER BY '".$search."' DESC 
        LIMIT $start, $per_page ";

$statement = $mysqli -> prepare($query);
$statement -> execute();
$rs=$statement -> get_result();
if ($rs -> num_rows == 0 ) {
    echo "<p>No results were found </p>";
    if ($rs -> num_rows > 0  ) {
        while (strlen($query)>1  &&   $row = $rs -> fetch_assoc()){
            echo  $row['title'] . '</a>';
            echo '<br/>'.$row['url'];
            echo '<br/>'.$row['description'];  
        }
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Little Note: `$var` will automatically be expanded in a double quoted literal. That knowledge should make your code easier to read/code and less likely to have errors – RiggsFolly Sep 19 '16 at 19:38
  • 1
    Your script is at risk of [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Have a look at what happened to [Little Bobby Tables](http://bobby-tables.com/) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly Sep 19 '16 at 19:39

1 Answers1

0

MySQL restrict fulltext search if the keyword is too short, I believe it return a result because "york" is 4 letter long and only because of that.

You may change that behavior in the my.ini config file, or another way (database local config)

http://dev.mysql.com/doc/refman/5.7/en/fulltext-fine-tuning.html

Proger_Cbsk
  • 362
  • 3
  • 12