SQL Server语句分页+页面代码

select * from( select ROW_NUMBER() over(order by 主标识 desc)RowId,* FROM
(

--单表分页
select 字段名 from 表名 where 条件

--多表分页
select 字段名 from 表1 as a,表2 as b where a.id=b.id and 条件

) t
) tt
WHERE RowId BETWEEN 数量*(页数-1)+1 and (数量*页数)
--总数量
select count(*) from 表名
--总页数
select (count(*)/条数) from 表名

 

HTML代码

<!--当前页码-->
<input  type="hidden" value="1" id="index"/>
<!--显示数量-->
<input  type="hidden" value="0" id="ListCount" />
<!--总页数-->
<input  type="hidden" value="0" id="PageMax" />
<div class="page" style="text-align: center;">
    <a href="javascript:;" class="firstPage pagea" onclick="PageClick('1')">首页</a>
    <a href="javascript:;" class="prevPage pagea" onclick="PageClick('-')">上一页</a>
    <span class="pageBody"></span>
    <a href="javascript:;" class="prevPage pagea" onclick="PageClick('+')">下一页</a>
    <a href="javascript:;" class="firstPage pagea wy" onclick="PageClick('1')">尾页</a>
</div>
$(function () {
    //查询数据, Ajax查询数据(获取页数,请求URL传需查询的页数),得出结果数量并赋值隐藏域  $("#ListCount").val(item.Count);
    GetList();
    //获取 共有几页并绑定分页
    getPageMax(1);
})
//分页单机事件
function PageClick(page) {
    var index = $("#index").val() * 1;
    var PageMax = $("#PageMax").val() * 1;
    if (page == "+") {
        if (index < PageMax)
            $("#index").val(index + 1)
    }
    else if (page == "-") {
        if (index > 1)
            $("#index").val(index - 1)
    }
    else {
        $("#index").val(page)
    }

    index = $("#index").val() * 1;

    $(".oncalass").addClass("pagea");
    $(".oncalass").removeClass("oncalass");
    $(".page_" + index + "").addClass("oncalass").removeClass("pagea");
    getPageMax(index);
    GetList();
}
//获取 共有几页并绑定分页
function getPageMax(page) {
    var ListCount = $("#ListCount").val();
   //10表示每次查询数量
    var count = Math.ceil(ListCount / 10);

    $("#PageMax").val(count);

    $(".wy").attr("onclick", "PageClick('" + count + "')");
    var CountS = [];

    if (count < 6) {
        for (var i = 1; i < (count + 1) ; i++) {
            CountS.push(i);
        }
    }
    else if (page >= (count - 2)) {
        for (var i = (count - 4) ; i < (count + 1) ; i++) {
            CountS.push(i);
        }
    }
    else if (page <= 3) {
        CountS = [1, 2, 3, 4, 5];
    }

    else {
        var si = page - 2;
        var ei = page + 3
        for (var i = si ; i < ei ; i++) {
            CountS.push(i);
        }
    }


    var htmla = ""
    $.each(CountS, function (index, item) {
        var cla = "pagea";
        if (item == page) cla = "oncalass"
        htmla += "<a href=\"javascript:;\" class=\"" + cla + " page_" + item + "\" onclick=\"PageClick('" + item + "')\">" + item + "</a>";
    })
    $(".pageBody").html(htmla)

}
.page a {
    display: inline-block;
    width: 50px;
    height: 35px;
    line-height: 35px;
    text-align: center;
    margin: 0 0.05rem;
    background-color: #fff;
    font-family: "Arial";
    border-radius: 3px;
    border: 1px solid #e8e8ec;
}
function GetList() {
    $("#List").html("");
    var index = $("#index").val();//当前页
    var ListCount = $("#ListCount").val();//总数量
    var url = "{%#path%}?xmls=xmls/goods.xmls&method=GetList&index=" + index;
    $.ajax({
        type: 'GET', url: url, async: false, data: { ListCount: ListCount }, success: function (ret) {

            var item = JSON.parse(ret)
            if (item.ListCount != 0) {
                $("#ListCount").val(item.ListCount);
                $(".page").show()
            } else {
                $(".page").hide();
            }

            var json = JSON.parse(item.center);
            $.each(json, function (index, item) {
                var html = "";
                html += '<tr>';
                $("#List").append(html)
            })

        }

    })
}

 

posted @ 2019-10-23 10:16  时光博客  阅读(369)  评论(0编辑  收藏  举报