PHP 搜索框如何多条件查询??
逆向行走
逆向行走 2019-06-20 16:48:02
[PHP讨论组]

本人PHP新手。在写搜索框内容的时候发现不能多条件同时查询,请哪位给个思路该怎么写。不胜感激搜索框.png


下面是写的PHP内容:

                                 $inquire = "select count(*) as total from tb_file where f_type=1"; //查找已发布的内容

                                 $sql = mysqli_query($conn,$inquire);

                                 $result = mysqli_fetch_assoc($sql);

                                 $total = $result['total'];

                                 if ($total == 0) {//如没有已发布的内容提示重新搜索

                                    ?>

                                   

                                       暂无查询内容,请重新搜索

                                   

                                   

                                 }else{

                                    $page = new Page(20, $total);//分页类


                                    //重点是这里!!如何多条件同时查询

                                    $inquireCon = "select * from tb_file where f_qualitynum like '%$fileNum%' or f_filename like '%$fileName%' or f_department='$department' or f_classify='$qualityfile' order by f_date desc limit ".$page->limit()."";



                                    $sqlCon = mysqli_query($conn, $inquireCon);

                                    while($resultCon = mysqli_fetch_assoc($sqlCon)){

                                       ?>

                                       

                                           

                                           

                                           

                                           

                                           

                                           

                                           

                                           

                                       

                                       

                                    }

                                 }

                              ?>


逆向行走
逆向行走

全部回复(3)
WJ
if (strlen($SO['cate_id'])) {
    $filter[] = [
        'cate_label', 'like', "%," . trim($SO['cate_id']) . ",%"
    ];
}
if (strlen($SO['audit'])) {
    $filter[] = [
        'audit', '=', $SO['audit']
    ];
}
if ($SO['title']) {
    $filter[] = [
        'title', 'like', "%" . trim($SO['title']) . "%"
    ];
}

看看类似这样的行不行 这是tp的写法  原生的就用拼接  原生好久没写了

逆旅行人

根据get到的数据,不是空的话,拼接条件就好了

逆向行走

顶上去,如有知道的希望多多帮助。感谢

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号