0

my search query is:

SELECT * FROM `trades` where `app` = '1' AND (`unit` LIKE '%$search%' OR `keyword` LIKE '%$search%')
while($row = mysql_fetch_array($sql )){

and after it i need to compare and show like this:

similar_text(strtoupper($search), strtoupper($row['unit']), $similarity_pst);
  if (number_format($similarity_pst, 0) > 20){
echo $row['link'];
echo $row['unit'];
echo $row['keyword'];
//....

but i want before print value, sort all of in $row by percent on top 90% and then show 80 ...70% and can show with pagination thanks

shahriyar3
  • 33
  • 1
  • 6

1 Answers1

0

Be aware when using this function, that the order of passing the strings is very important if you want to calculate the percentage of similarity, in fact, altering the variables will give a very different result.

Example:

<?php 
    $var_1 = 'PHP IS GREAT'; 
    $var_2 = 'WITH MYSQL'; 

    similar_text($var_1, $var_2, $percent); 

    echo $percent; 
    // 27.272727272727 

    similar_text($var_2, $var_1, $percent); 

    echo $percent; 
    // 18.181818181818 
?>

You may also see the topic, discussed here: How to find similar results and sort by similarity?

Community
  • 1
  • 1
Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52