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
$Model = M(); Just add a slash when instantiating and query can be used
query method does not exist, that means $crossingModel is not a model, try printing $crossingModel
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)
{
}
3 Then your limit can be written like this
->limit($pagearr['start'],$pagearr['pagesize'])