首页 > 编程 > PHP > 正文

联合查询thinkPHP

2020-03-22 19:31:45
字体:
来源:转载
供稿:网友
  • html' target='_blank'>public function trace() {
    $page = I('get.p');
    $page = $page ? $page : 1;
    $start = ($page - 1) * 10;
    $where['a.uid'] = session('ip');
    if (I('get.')) {
    $data = I('get.');
    $this->assign('get', $data);
    if (empty($data['starttime']) ^ empty($data['endtime'])) {
    $this->success('时间不能单独为空', 'trance');exit;
    }
    if ($data['starttime'] > $data['endtime']) {
    $this->success('时间选择错误', 'trance');exit;
    }
    //组装时间的where条件
    if (!empty($data['starttime'])) {
    $starttime = strtotime($data['starttime']);
    $endtime = strtotime($data['endtime']);
    $where['b.lastupdate'] = array('between', $starttime . "," . $endtime);
    }


    //组装工单状态的判断条件
    switch ($data['status']) {
    case 1:
    # code...
    $where['e.ostatus'] = 1;
    break;


    case 2:
    # code...
    $where['e.ostatus'] = 2;
    break;
    default:
    break;
    }
    //查询结果
    $count = M('phpyun_expect_order a')
    ->field('count(*) as count')
    ->join("left join phpyun_resume_expect as b on(a.eid = b.id) left join phpyun_job_class c on (b.job_classid = c.id) left join phpyun_resume d on (b.uid = d.uid) LEFT JOIN phpyun_member e on(e.uid = a.memberid) left join phpyun_channels f on (e.otro=f.num)")
    ->where($where)
    ->find();
    $list = M('phpyun_expect_order a')
    ->field('a.eid,a.memberid,a.count,b.integrity,b.name as ename,c.name as jobname,b.lastupdate,d.name,d.telphone,e.otro,e.mstatus,e.ostatus as order_status,f.name as qrname,h.name as username')
    ->join("left join phpyun_resume_expect as b on(a.eid = b.id) left join phpyun_job_class c on (b.job_classid = c.id) left join phpyun_resume d on (a.memberid = d.uid) LEFT JOIN phpyun_member e on(e.uid = a.memberid) left join phpyun_channels f on (e.otro=f.num) left join data_users h on(a.uid=h.id)")
    ->where($where)
    ->group('a.memberid')
    ->order('b.integrity desc')
    ->limit($start . ",10")
    ->select();
    } else {
    $count = M('phpyun_expect_order a')->field("count(*) as count")->where($where)->find();
    $list = M('phpyun_expect_order a')->field('a.eid,a.memberid,a.count,b.integrity,b.name as ename,c.name as jobname,b.lastupdate,d.name,d.telphone,e.otro,e.mstatus,e.ostatus as order_status,f.name as qrname,h.name as username')->join("left join phpyun_resume_expect as b on(a.eid = b.id) left join phpyun_job_class c on (b.job_classid = c.id) left join phpyun_resume d on (a.memberid = d.uid) LEFT JOIN phpyun_member e on(e.uid = a.memberid) left join phpyun_channels f on (e.otro=f.num) left join data_users h on(a.uid=h.id)")->order('b.integrity desc')->where($where)->group('a.memberid')->limit($start . ",10")->select();


    }
    $this->assign('data', $list);
    $Page = new ThinkPage($count['count'], 10); // 实例化分页类 传入总记录数和每页显示的记录数
    if ($where) {
    foreach ($where as $k => $v) {
    $Page->parameter[$k] = urlencode($v);
    }
    }
    $show = $Page->show(); // 分页显示输出
    $this->assign('page', $show);
    $this->assign('count', $count['count']);
    $this->assign('nowpage', $page);
    $this->display();
    }PHP编程

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表