tp3 搜索 分页一套

本文详细介绍了如何在TP3框架下实现高效搜索引擎及分页功能,包括查询条件构造、数据库操作优化、分页参数设置等内容,帮助开发者提升应用的用户体验和性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

  public function index()
    {
        $param = I('');
        //搜索条件
        $param['job'] ? $where['job'] = ['like', '%' . trim($param['job'] . '%')] : '';

        //月薪范围
        $monthly_pay = explode('至', $param['monthly_pay']);
        switch ($param['monthly_pay']) {
            case '2':
                $where['monthly_pay2'] = ['lt', 3];
                break;
            case '2-5':
                $where['monthly_pay2'] = ['gt', 2];
                break;
            case '5-10':
                $where['monthly_pay2'] = ['gt', 5];
                break;
            case '10-15':
                $where['monthly_pay2'] = ['gt', 10];
                break;
            case '15-25':
                $where['monthly_pay2'] = ['gt', 15];
                break;
            case '25-50':
                $where['monthly_pay2'] = ['gt', 25];
                break;
            case '50':
                $where['monthly_pay1'] = ['gt', 49];
                break;
        }

        //工作经验
        $experience = explode('至', $param['experience']);
        switch ($param['experience']) {
            case '1':
                $where['experience2'] = ['lt', 2];
                break;
            case '1-3':
                $where[0] = 'experience1>=1 AND experience2<=3';
                break;
            case '3-5':
                $where[0] = 'experience1>=3 AND experience2<=5';
                break;
            case '5-10':
                $where[0] = 'experience1>=5 AND experience2<=10';
                break;
            case '10':
                $where['experience2'] = ['gt', 9];
                break;
        }

        //学历
        $param['education'] ? $where['education'] = $param['education'] : '';
        $param['status'] ? $where['p.status'] = $param['status'] : '';
        $ctime = explode('至', $param['ctime']);
        $param['ctime'] ? $where['p.ctime'] = [['gt', strtotime($ctime[0])], ['lt', strtotime($ctime[1])]] : '';

        //清空
        if ($param['clear']) {
            unset($param);
        }
        $count = M('recruit_position')->alias('p')->join('ys_recruit_company  AS c ON p.cid=c.id', 'left')->where($where)->count();
        $Page = new \Think\Page($count, 10);
//        $res = M('shop_order')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)
//            ->select();
//        $data = array_map(function ($v) {
//            $v['items'] = json_decode($v['items'], true);
//            return $v;
//        }, $res);

        $res = M('recruit_position')->alias('p')
            ->field('p.*,c.name,c.logo,c.address')
            ->join('ys_recruit_company  AS c ON p.cid=c.id', 'left')
            ->where($where)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->order('ctime desc')
            ->select();
        
        $this->assign([
            'data' => $res,
            'job' => $param['job'],
            'monthly_pay' => $param['monthly_pay'],
            'experience' => $param['experience'],
            'education' => $param['education'],
            'ctime' => $param['ctime'],
            'status' => $param['status'],
            'page' => $Page->show()
        ]);
        $this->display();
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值