tp5 union 分頁 排序
阿新 • • 發佈:2018-12-17
//構建訊息表子查詢 $sql = Db::table(DB_PREFIX.'message') ->field('a.id,c.title,c.create_time,c.type,a.tab,a.status') ->alias('a') ->where($my_where) ->join(DB_PREFIX.'message_text c', 'a.text_id = c.id','left') ->buildSql(); //構建sys表 union 聯合 $data = Db::table(DB_PREFIX.'sys_message') ->alias('a') ->field('a.id,c.title,c.create_time,c.type,a.tab,a.status') ->join([[DB_PREFIX . 'message b', 'a.message_id = b.id','left'], [DB_PREFIX . 'message_text c', 'c.id = b.text_id','left']]) ->union($sql,true) ->where($sys_where) ->buildSql(); //獲得查詢結果 $list = Db::table($data.' as a') ->order('a.create_time desc') ->paginate($page,false,['query'=>request()->param()]);
利用字查詢 分頁 field 欄位必須一致