dougou8573 2019-05-11 17:59
浏览 65

如何按查询排序mysql结果?

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???

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料