zoukankan      html  css  js  c++  java
  • PHP+sqlsrv的分页实现

    <?php
    //A表 分页,总记录,输出
    /////////////////////每一页的数据数量
    $messagecount= intval($_GET['messagecount']);
    //////////////////要搜索第几页的数据
    $currentpageindex= intval($_GET['currentpageindex']);

    class Emp_ {
    public $ID="";
    public $UpdateTime="";
    public $PageNumber="";
    }

    $sql="SELECT TOP
    ( ? ) *,
    ( SELECT COUNT ( ID ) FROM A WHERE B = '321' ) AS COUNT
    FROM
    A
    WHERE
    B = '321'
    AND ID NOT IN (
    SELECT TOP
    ( (?) * (?) ) ID
    FROM
    A
    WHERE
    B = '321')";

    $params = array($messagecount,$messagecount,$currentpageindex);

    $result= sqlsrv_query($conn,$sql,$params);
    if(!$result)
    {
    echo "Error in executing statement 1. ";
    $arr = array('Result' => 0);
    echo json_encode($arr);
    die( print_r( sqlsrv_errors(), true));
    }

    if(sqlsrv_rows_affected($result)==0){
    $arr = array('result' => '0');
    echo json_encode($arr);
    //
    sqlsrv_close($conn);
    die( print_r( sqlsrv_errors(), true));
    }
    else{
    $datalist=array();
    while($row = sqlsrv_fetch_array($result))
    {
    $e = new Emp_ ();
    $e->ID = iconv("GB2312//IGNORE", "UTF-8", $row["ID"]) ;
    $e->UpdateTime=get_object_vars($row["UpdateTime"])["date"];
    $e->PageNumber=ceil($e->COUNT/$messagecount) ;
    array_push($datalist,$e);
    //$data= json_encode($e,JSON_UNESCAPED_UNICODE);
    // echo $data;

    }
    echo json_encode(array('result' => 'ok','information'=>$datalist),JSON_UNESCAPED_UNICODE);

    }
    sqlsrv_free_stmt($result);
    sqlsrv_close($conn);

    ?>


  • 相关阅读:
    Maya 与 Matlab 数据互联插件使用教程
    代码可视化算法流程
    sql 至少含有
    sql update limit1
    c# windows service 程序
    c#和.net区别
    c#数据库乱码
    c#事件实质
    c#非界面线程控制控件
    mysql唯一查询
  • 原文地址:https://www.cnblogs.com/summerGraden/p/11138209.html
Copyright © 2011-2022 走看看