2

I am trying to make a search page whereby I can order results by their similarity to the search query

$search_query = 'this is the users search query'; 
$sql =$mysqli->query("SELECT column_name  
                      FROM table_name 
                      WHERE column_name LIKE $search_query  
                      **ORDER BY SIMILARITY TO $search_query**");

I have tried using the php similar_text() function as follows

while($row= $sql->fetch_object()){
    $percent = similar_text($search_query,$row->column_name,$percent);
    $sql_results =$mysqli->query("SELECT column_name  
                                  FROM table_name   
                                  ORDER BY $percent");

    while($row = $sql_results->fetch_object()){
        echo // results
    }
}

though I am entirely sure that this is not the best way to do this and after much searching with no solutions I posted here. Any help would be awesome thanks!

wogsland
  • 7,351
  • 16
  • 46
  • 79
  • 1
    found an answer on this page [here](http://stackoverflow.com/questions/6259647/mysql-match-against-order-by-relevance-and-column) –  Jan 22 '16 at 19:26
  • sorry for the duplicate –  Jan 22 '16 at 19:27

0 Answers0