dongxing8009 2012-11-13 09:48
浏览 55

比较后搜索和排序查询输出

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

  • 写回答

1条回答 默认 最新

  • doubo4824 2012-11-13 09:58
    关注

    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?

    评论

报告相同问题?