登录

PHP 搜索框如何多条件查询??

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


下面是写的PHP内容:

<?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) {//如没有已发布的内容提示重新搜索

                                    ?>

                                    <tr>

                                       <td colspan="8" class="text-center">暂无查询内容,请重新搜索</td>

                                    </tr>

                                    <?php

                                 }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)){

                                       ?>

                                       <tr>

                                           <td class="text-center" style="vertical-align: middle;"><input type="checkbox" name=""></td>

                                           <td class="text-center" style="vertical-align: middle;"><?php echo $resultCon['f_qualitynum']; ?></td>

                                           <td class="text-center" style="vertical-align: middle;"><?php echo $resultCon['f_filename']; ?></td>

                                           <td class="text-center" style="vertical-align: middle;"><?php echo $resultCon['f_classify']; ?></td>

                                           <td class="text-center" style="vertical-align: middle;"><?php echo $resultCon['f_grade']; ?></td>

                                           <td class="text-center" style="vertical-align: middle;"><?php echo $resultCon['f_department']; ?></td>

                                           <td class="text-center" style="vertical-align: middle;"><?php echo $resultCon['f_date']; ?></td>

                                           <td class="text-center" style="vertical-align: middle;"><input type="text" name="download" class="btn btn-default btn-xs" style="width: 50%;" value="下载" style="width: 80%;"></td>

                                        </tr>

                                       <?php

                                    }

                                 }

                              ?>


# PHP
逆向行走 逆向行走 1762 天前 1626 次浏览

全部回复(3) 我要回复

  • WJ

    WJ2020-05-27 17:14:36

    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的写法  原生的就用拼接  原生好久没写了

    回复
    0
  • 逆旅行人

    逆旅行人2019-06-22 22:56:37

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

    回复
    0
  • 逆向行走

    逆向行走2019-06-21 09:21:52

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

    回复
    0
  • 取消 回复 发送