mysql – Probleme mit kohärentem Betrieb in ThinkPHP3.2.3?
过去多啦不再A梦
过去多啦不再A梦 2017-07-05 10:46:05
0
3
927

Code


Die SQL-Anweisung lautet
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 trk.devs_other WHERE type = 101 )

Was ich möchte ist
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
Diese Daten Können Sie mir bitte sagen, wie man einen kohärenten Code schreibt? ? ?

Und bei der Verwendung von nativem SQL wird immer gemeldet, dass die Abfragemethode nicht existiert

过去多啦不再A梦
过去多啦不再A梦

Antworte allen(3)
ringa_lee

$Model = M(); 实例化时加个斜杠就好了 query就可以用了

扔个三星炸死你

query方法不存在,那就说明$crossingModel不是model,打印$crossingModel试试看

洪涛

方法一
使用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'])

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage