mysql 两个不关联的表 列表分页

代码框架 tp5

代码示例

        if ($type == 1) {
            $sql = "SELECT uid,money,get_time,expire_time,change_time,status,invited_uid,remark,maxMoney,1 AS type,change_id,0 AS withdraw_id FROM pubm_coin_changeup_ticket " . $where;
            $countSql = "SELECT count(*) AS total FROM pubm_coin_changeup_ticket " . $where;
        } elseif ($type == 2) {
            $sql = "SELECT uid,money,get_time,expire_time,change_time,status,0 AS invited_uid,remark,maxMoney,2 AS type,0 AS change_id,withdraw_id  FROM pubm_cash_drawup_ticket " . $where;
            $countSql = "SELECT count(*) AS total FROM pubm_cash_drawup_ticket " . $where;
        } else {
            $sql = "SELECT uid,money,get_time,expire_time,change_time,status,0 AS invited_uid,remark,maxMoney,2 AS type,0 AS change_id,withdraw_id  FROM pubm_cash_drawup_ticket " .
                $where . " UNION ALL SELECT uid,money,get_time,expire_time,change_time,status,invited_uid,remark,maxMoney,1 AS type,change_id,0 AS withdraw_id FROM pubm_coin_changeup_ticket " .
                $where;
            $countSql = "SELECT SUM(a.b) AS total FROM ( SELECT COUNT(*) AS b FROM pubm_coin_changeup_ticket " . $where .
                " UNION SELECT COUNT(*) AS b FROM pubm_cash_drawup_ticket " . $where . ") AS a";
        }
        $sql .= ' order by get_time desc';
        if ($limit > 0) {
            $sql .= ' limit ' . $offset . ',' . $limit;
        }
        $data = Db::query($sql);
        if ($count == 0 && $limit > 0) {
            $countData = Db::query($countSql);
            $count = $countData[0]['total'];
        }
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐