程式碼
SQL語句為
SELECT crsIpint
,crsIpout
,crsName
#,wfdz
,CheckStatus
,0 AS flag FROM vehicle.crossing AS t1 LEFT JOIN ( SELECT * FROM caminfo.devs_ip_status WHERE type
= 95 ) AS t2 ON( t1.crsId = t2 .DeviceID ) WHERE t1.type <> 0 LIMIT 0,20 UNION ( SELECT ip AS crsIpint,"" AS crsIpout,name AS crsName,"主伺服器" AS wfdz,1 AS CheckStatus,1 AS flag FROM crsName,"主伺服器" AS wfdz,1 AS CheckStatus,1 AS flag FROM crsName WHERE type
= 101 )
我想要的是
SELECT crsIpint
,crsIpout
,crsName
,wfdz
,CheckStatus
,0 AS flag FROM vehicle.crossing AS t1 LEFT JOIN ( SELECT * FROM caminfo.devs_ip_status WHERE type
= 95 ) AS t2 ON( t1.crsId = t2.DeviceID ) WHERE t1.type < ; 0 UNION ( SELECT ip AS crsIpint,"" AS crsIpout,name AS crsName,"主伺服器" AS wfdz,1 AS CheckStatus,1 AS flag FROM trk.devs_other WHERE type
= 101 ) LIMIT 0, 20
這個資料請問各位大神程式碼連貫操作該怎麼寫? ? ?
而且用原生SQL 總是報query方法不存在
PHP中文网2017-07-05 10:48:05
方法一
使用query
$sql='';//原生的sql 語句
$res = M()->query($sql);
方法二:
1 $count=M('')-join ()->where($where)->count();//取得總記錄數
//$page 頁碼10每頁顯示資料
2 $pagearr=getPageArr($page,10,$count);
/ /分頁使用的方法建議放在common 中
function getPageArr($page, $pagesize = 10, $count)
{
$page = isset($page) ? abs(intval($page)) : 1;
$pagesize = isset($pagesize) ? abs(intval($pagesize)) : 10;
$page > 100000 && $page = 100000;
$pagesize > 100 && $page = 100;
$pagetotal = ceil($count / $pagesize);
($page > $pagetotal) && ($page = $pagetotal);
($page < 1) && ($page = 1);
//下一页
if ($page > $pagetotal) {
$nextpage = $pagetotal;
} else {
$nextpage = $page + 1;
}
//上一页
if ($page > 1) {
$prevpage = $page - 1;
} else {
$prevpage = $page;
}
$pagearr = array(
"page" => $page,
"pagesize" => $pagesize,
"pagetotal" => $pagetotal,
"count" => $count,
"start" => ($page - 1) * $pagesize,
"nextpage" => $nextpage,
"prevpage" => $prevpage,
);
return $pagearr;
}
3 然後你的limit可以這樣寫了
->limit($pagearr['start'],$pagearr['pagesize'])