Heim  >  Fragen und Antworten  >  Hauptteil

mysql – Probleme mit kohärentem Betrieb in ThinkPHP3.2.3?

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梦2687 Tage vor925

Antworte allen(3)Ich werde antworten

  • ringa_lee

    ringa_lee2017-07-05 10:48:05

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

    Antwort
    0
  • 扔个三星炸死你

    扔个三星炸死你2017-07-05 10:48:05

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

    Antwort
    0
  • PHP中文网

    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'])

    Antwort
    0
  • StornierenAntwort