分頁設計
① 網頁設計中如何實現分頁的效果
用GridView空間,裡面有自帶的分頁功能,將屬性設置為true,然後在相應的事件裡面寫資料庫的查詢代碼就可以了!
一、動態網頁:這里有一段PHP代碼,供參考,我這邊運行成功:
1.顯示內容部分
<?php
$page=$_GET["page"];
if($page=="")
{$page=1;}
if(is_numeric($page))
{
$page_size=30;
$query="select count(*) as total from solution order by id desc";
$result = mysql_db_query($dbn, $query);
$message_count=mysql_result($result,0,"total");
$page_count=ceil($message_count/$page_size);
$offset=($page-1)*$page_size;
$sql=mysql_db_query($dbn,"select * from solution order by id desc limit $offset,$page_size");
$row=mysql_fetch_object($sql);
if(!$row)
{
echo("No data!");
}
?>
<?php
do
{
?>
</p>
<p>+ <a href="<?php echo $row->pageurl; ?>.html" title="<?php echo $row->pagetitle; ?>"><?php echo $row->pagetitle; ?></a></p>
<?php
}while($row=mysql_fetch_object($sql));
?>
<?php
}
?>
2.分頁部分
<?php
if($page!=1)
{
echo "<a href=index.php?page=1>First</a> ";
echo "<a href=index.php?page=".($page-1).">Previous</a> ";
}
if($page<$page_count)
{
echo "<a href=index.php?page=".($page+1).">Next</a> ";
echo "<a href=index.php?page=".$page_count.">End</a>";
}
?>
</span> <span> Current Page:<?php echo $page;?> / <?php echo $page_count;?></span>
<?php
mysql_free_result($sql);
?>
二、靜態網頁用js:
用JavaScript偽分頁,實際上內容還是在同一個頁面上。
<div id="page_1">第1頁內容</div>
<div id="page_2">第2頁內容</div>
<div id="page_3">第3頁內容</div>
<div id="page_4">第4頁內容</div>
<script type="text/javascript">//<![CDATA[
var curpage=document.hash.substr(1);
for (var i=1;i<=4;++i) {
document.getElementById('page_'+i).style.display=(i==curpage)?'':'none';
}
//]]></script>
然後用 page.htm#1 page.htm#2 page.htm#3 page.htm#4 來鏈接4頁。
② 在問卷星中設計問卷的時候,分頁欄是怎麼用的
可以查看幫助:分頁欄使用
③ JPress 中如何設計分頁顯示的條目
if Rs.RecordCount>0 then page=clng(request("page")) rszs=rs.recordcount Rs.PageSize=15 if page=0 then page=1 pages=Rs.pagecount if page > pages then page=pages Rs.AbsolutePage=page For i=1 to Rs.PageSize 循環數據 rs.movenext
④ java前段分頁怎麼設計
ListAction.java
packagecom.sy.action;
importjava.util.List;
importcom.opensymphony.xwork2.ActionSupport;
importcom.sy..AdminDao;
importcom.sy..NewsDao;
importcom.sy..impl.AdminDaoImpl;
importcom.sy..impl.NewsDaoImpl;
importcom.sy.vo.Admin;
importcom.sy.vo.News;
{
=1L;
inti=1;//中間變數
privateintk;//儲存最大頁面數
privateintpageNow=1;//頁碼數,初始為
privateintpageSize=5;//頁面行數
privateintintRowCount;//總行數
privateintintPageCount;//總頁數
privateAdminadmin;
privateList<Admin>Adminss;
privateNewsnews;
@SuppressWarnings("unchecked")
privateList<News>Newss;
privateintid;
privateintaid;
publicNewsgetNews(){
returnnews;
}
publicvoidsetNews(Newsnews){
this.news=news;
}
@SuppressWarnings("unchecked")
publicList<News>getNewss(){
returnNewss;
}
publicvoidsetNewss(List<News>newss){
Newss=newss;
}
publicintgetId(){
returnid;
}
publicvoidsetId(intid){
this.id=id;
}
publicAdmingetAdmin(){
returnadmin;
}
publicvoidsetAdmin(Adminadmin){
this.admin=admin;
}
publicList<Admin>getAdminss(){
returnAdminss;
}
publicvoidsetAdminss(List<Admin>adminss){
Adminss=adminss;
}
publicintgetAid(){
returnaid;
}
publicvoidsetAid(intaid){
this.aid=aid;
}
publicintgetPageNow(){
returnpageNow;
}
publicvoidsetPageNow(intpageNow){
this.pageNow=pageNow;
}
publicintgetPageSize(){
returnpageSize;
}
publicvoidsetPageSize(intpageSize){
this.pageSize=pageSize;
}
publicintgetIntRowCount(){
returnintRowCount;
}
publicvoidsetIntRowCount(intintRowCount){
this.intRowCount=intRowCount;
}
publicintgetIntPageCount(){
returnintPageCount;
}
publicvoidsetIntPageCount(intintPageCount){
this.intPageCount=intPageCount;
}
publicintgetK(){
returnk;
}
publicvoidsetK(intk){
this.k=k;
}
@SuppressWarnings("unchecked")
@Override
//顯示新聞列表
publicStringexecute()throwsException{
NewsDaonpage=newNewsDaoImpl();
intRowCount=npage.count();
k=(intRowCount+pageSize-1)/pageSize;
intPageCount=(intRowCount+pageSize-1)/pageSize;//計算出總頁數
if(pageNow<1){
pageNow=1;
}
if(pageNow>intPageCount)
pageNow=intPageCount;
i=(pageNow-1)*pageSize;
NewsDaonlist=newNewsDaoImpl();
if(null!=nlist.queryByPage(i,pageSize)){
Newss=nlist.queryByPage(i,pageSize);
returnSUCCESS;
}else{
return"failure";
}
}
..
}
listNews.jsp
<%@pagelanguage="java"pageEncoding="UTF-8"%>
<%@taglibprefix="s"uri="/struts-tags"%>
<%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"://"
+request.getServerName()+":"+request.getServerPort()
+path+"/";
%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
<html>
<head>
<basehref="<%=basePath%>">
<title>MyJSP'index.jsp'startingpage</title>
</head>
<body>
..
<center>
共<s:propertyvalue="intRowCount"/>記錄
第<s:propertyvalue="pageNow"/>頁
<s:urlid="url_pre"value="list.action">
<s:paramname="pageNow"value="pageNow-1"></s:param>
</s:url>
<s:urlid="url_next"value="list.action">
<s:paramname="pageNow"value="pageNow+1"></s:param>
</s:url>
<s:iteratorvalue="Newss"status="status">
<s:urlid="url"value="list.action">
<s:paramname="pageNow"value="pageNow"/>
</s:url>
</s:iterator>
<s:iftest="pageNow==1">
<s:ahref="%{url_pre}">最前一頁</s:a>
</s:if>
<s:else>
<s:ahref="%{url_pre}">上一頁</s:a>
</s:else>
<s:iftest="pageNow==k">
<s:ahref="%{url_next}">最後一頁</s:a>
</s:if>
<s:else>
<s:ahref="%{url_next}">下一頁</s:a>
</s:else>
</center>
</body>
</html>
NewsDao.java
packagecom.sy..impl;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjava.text.SimpleDateFormat;
importjava.util.ArrayList;
importjava.util.List;
importcom.sy..NewsDao;
importcom.sy.util.DataBaseConnection;
importcom.sy.util.StringUtil;
importcom.sy.vo.News;
{
//獲取分頁新聞列表
@SuppressWarnings("unchecked")
publicList<News>queryByPage(inti,intpageSize){
List<News>newss=newArrayList();
PreparedStatementpstmt=null;
Stringsql=null;
ResultSetrs=null;
DataBaseConnectiondbc=null;
dbc=newDataBaseConnection();
sql="select*"+i+","+pageSize;
try
{
pstmt=dbc.getConnection().prepareStatement(sql);
rs=pstmt.executeQuery();
while(rs.next())
{
Newsnews=newNews();
news.setId(rs.getInt("id"));
news.setName(rs.getString("name"));
news.setTitle(rs.getString("title"));
news.setDate(rs.getString("date"));
news.setEmail(rs.getString("email"));
news.setContent(rs.getString("content"));
i++;
newss.add(news);
}
rs.close();
pstmt.close();
}
catch(Exceptione)
{
System.out.println(e);
}
finally
{
dbc.close();
}
returnnewss;
}
//查詢總行數
publicintcount(){
intintRowCount=0;//總行數
PreparedStatementpstmt=null;
Stringsql=null;
ResultSetrs=null;
DataBaseConnectiondbc=null;
dbc=newDataBaseConnection();
sql="selectcount(id)fromstruts2neworderbyidasc";
try
{
pstmt=dbc.getConnection().prepareStatement(sql);
rs=pstmt.executeQuery();
rs.next();//游標指向第一行
intRowCount=rs.getInt(1);//取得總行數
rs.close();
pstmt.close();
}
catch(Exceptione)
{
System.out.println(e);
}
finally
{
dbc.close();
}
returnintRowCount;
}
}
⑤ asp.net 網頁分頁設計
有兩種方法:
1、GridView控制項自抄帶的分頁功能,方便快捷,不過缺點很明顯,性能差。
2、自己寫,自己寫的話就需要SQl方面的知識了,最好寫個存儲過程,在存儲過程中設兩個參數,一個是存儲頁的大小,一個存儲當前頁碼。這樣每次給它不同的值就能實現分頁查詢數據了。
⑥ PCB設計如何使用分頁連接符
頁碼不用填寫,是自動產生的。如果你不要顯示頁碼,可在Options(選項)--專Preferences(參數)的屬Milcellaneous(雜項)選項卡中,把Global Visibility前的方框復選勾去掉。
⑦ java分頁設計,急!
一個BBS資料庫,你將相關資料庫查詢語句改改,應該就行了(文件名ShowArticleFlat.jsp)
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@page import="java.sql.*" %>
<%
int pageSize = 3;//每一頁顯示信息的條數
String strPageNo = request.getParameter("pageNo");//接收傳入的頁碼
int pageNo; //當前的頁碼
if(strPageNo == null || strPageNo.equals("")) {
pageNo = 1;
} else {
try {
pageNo = Integer.parseInt(strPageNo.trim());
} catch(NumberFormatException e) {
pageNo = 1;
}
if(pageNo <= 0) {
pageNo = 1;
}
}
Class.forName("com.mysql.jdbc.Driver");//獲取資料庫驅動
String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
Connection conn = DriverManager.getConnection(url);//獲取資料庫連接
Statement stmtCount = conn.createStatement();
ResultSet rsCount = stmtCount.executeQuery("select count(*) from article where pid=0");
rsCount.next();
int totalRecords = rsCount.getInt(1);//獲得資料庫中的所有記錄數
int totalPages = totalRecords % pageSize == 0 ? totalRecords / pageSize : totalRecords / pageSize + 1;//總共分多少頁
if(pageNo > totalPages) { //如果接收的頁碼大於總頁碼,那麼就將頁碼設置成最大頁碼
pageNo = totalPages;
}
int startPos = (pageNo - 1) * pageSize;
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where pid=0 order by pdate desc limit " + startPos + "," + pageSize);//獲取資料庫查詢結果集
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<a href="Post.jsp">發表新帖</a>
<table border="1">
<%
while(rs.next()) {
%>
<tr>
<td><%=rs.getString("title") %></td>
</tr>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</table>
共<%=totalPages %>頁 第<%=pageNo %>頁
<a href="ShowArticleFlat.jsp?pageNo=1">首頁</a>
<a href="ShowArticleFlat.jsp?pageNo=<%=pageNo-1%>">上一頁</a>
<a href="ShowArticleFlat.jsp?pageNo=<%=pageNo+1%>">下一頁</a>
<a href="ShowArticleFlat.jsp?pageNo=<%=totalPages%>">尾頁</a>
<form name="form1" action="ShowArticleFlat.jsp">
<select name="pageNo" onchange="document.form1.submit()">
<%
for(int i=1; i<=totalPages; i++) {
%>
<option value=<%=i%> <%=(pageNo == i) ? "selected" : ""%>>第<%=i%>頁</option>
<%
}
%>
</select>
</form>
<form name="form2" action="ShowArticleFlat.jsp">
輸入頁碼<input type="text" name="pageNo" value=<%=pageNo%>>
<input type="submit" value="GO">
</form>
</body>
</html>
⑧ 求解HTML分頁JS的設計和實現
這個用HTML也可以做用JS也可以做,不過這個功能是用後台完成的。
⑨ 如何設計api分頁
常規的分頁方式
API處理分頁看似簡單,實際上暗藏危機。最常見的分頁方式,大概是下面這樣的
/users/?page=1&limit=5
//服務端返回
{
"code": 0,
"pagination": {
"page": 1,
"limit": 5,
"total": 10
}
"data": {}
}
最理想的情況下,客戶端請求第一頁的5條數據,服務端如常返回,比如下圖:
拿Twitter的圖用一下,假設我們的資料庫有10條數據,按照5條一頁,正好有2頁。
在理想情況下,客戶端拉取數據時不會出現任何異常。但,這僅僅是正常情況,如果此時剛好有2條新數據插入。
資料庫記錄變為13。原來第二頁的數據是[5, 4, 3, 2, 1],現在變為[7, 6, 5, 4, 3],我們再一次拿到了第一頁的數據。同理,如果用戶在拉取數據時正好有數據被刪除,一樣會出現類似的問題。
根據item_id分頁
要解決此類問題,就不能使用常規的分頁方式。現在,我們換一個思路,客戶端拉取數據時不再傳page,改為item_id,我們就把它稱為max_id
/users/?max_id=5&limit=5
此時服務端就知道我們上次拉取到了item_id為5的數據,繼續在它後面拉取5條, 如下圖:
數據可以正常取回,不會再出現上一頁中的[6,7]。好了,讓我們再一次假設,此時又有8條數據插入了資料庫。再一次獲取數據
可以看出,再一次出現問題,我們又拿到了上一頁的[10,9]。所以,我們得告訴服務端,上一次拿到哪一條數據了。所以繼續增加一個since_id欄位。
恩,再一次取出了正確的數據。可能你覺得一切都正常了,但還是隱藏了一個致命的缺陷。
上面的數據能正常獲取,是因為數據都是一個有序的集合,如果數據無序,且從資料庫取出時需要按照某個欄位排序,那麼一切再次打回原點:所有的分頁都亂了。
如何設計分頁API
可以看出,兩種分頁方式都存在問題。所以這兩種需求都是必要的,我們需要根據不同的業務場景使用不同的分頁方式。
為了不造成客戶端的麻煩,我們對api的分頁做了一些更改。
{
"code": 0,
"pagination": {
"page": 1,
"next": {
"sinceId": 11,
"maxId": 11
//page: 1
},
"limit": 5,
"total": 10
},
"data": {}
}
我們由服務端來決定如何分頁,前端需要做的,只是把next欄位直接拼接到url中,這樣就可以應付各種分頁情況。