Code
SQL statement is
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,"Main Server" AS wfdz,1 AS CheckStatus,1 AS flag FROM trk.devs_other WHERE type
= 101 )
What I want is
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,"Main Server" AS wfdz,1 AS CheckStatus,1 AS flag FROM trk.devs_other WHERE type
= 101 ) LIMIT 0, 20
Could you please tell me how to write a coherent code for this data? ? ?
And when using native SQL, it always reports that the query method does not exist
ringa_lee2017-07-05 10:48:05
$Model = M(); Just add a slash when instantiating and query can be used
扔个三星炸死你2017-07-05 10:48:05
query method does not exist, that means $crossingModel is not a model, try printing $crossingModel
PHP中文网2017-07-05 10:48:05
Method one
Use query
$sql='';//Native sql statement
$res = M()->query($sql);
Method two:
1 $count=M('')- join()->where($where)->count();//Get the total number of records
//$page page number 10 displays data on each page
2 $pagearr=getPageArr($page,10,$count) ;
//The method used for paging is recommended to be placed in 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 Then your limit can be written like this
->limit($pagearr['start'],$pagearr['pagesize'])