I want to sort mysql results by like clause.
$query="select * from table where id!='a'";
if(!empty($getSearch)){
$search_exploded = explode ( " ", $getSearch );
$x = 0;
foreach($search_exploded as $search_each) {
$x++;
if( $x == 1 ){
$query .="and title LIKE '%$search_each%'";
} else{
$query .=" or title LIKE '%$search_each%'";
}
$sorting=" order by CASE WHEN title LIKE '%$search_each%' THEN 1 WHEN title LIKE '%$search_each%' THEN 2 else 3 end";
}
This code is working but it shows the results of everything matched with $search_each... I want to get the best results matched with the whole search i.e. $getSearch... but I also want to show related results if users misspell a word that's the reason I exploded $getSearch into $search_each... I'm confused can anybody help???