分页时把握好几个关键参数,形式是多种多样的。
当前页(currentPage)
页总数(totalPage)
总记录数(totalRecord)
每页记录数(pageSize)则可算出
首页firstPage = 1
未页lastPage=ceil(totalRecord/pageSize)
前一页 previousPage = currentPage - 1
后一页 nextPage = currentPage + 1
......
如果当前页为第1页,那么做1 2 3 4 5的链接时
分别在当前页加上指定的数字即可
"<a href='showPage.php?page=".($currentPage+1)."'>1</a>" .
"<a href='showPage.php?page=".($currentPage+2)."'>2</a>" .
"<a href='showPage.php?page=".($currentPage+3)."'>3</a>" .
"<a href='showPage.php?page=".($currentPage+4)."'>4</a>" .
"<a href='showPage.php?page=".($currentPage+5)."'>5</a>"
当前页(currentPage)
页总数(totalPage)
总记录数(totalRecord)
每页记录数(pageSize)则可算出
首页firstPage = 1
未页lastPage=ceil(totalRecord/pageSize)
前一页 previousPage = currentPage - 1
后一页 nextPage = currentPage + 1
......
如果当前页为第1页,那么做1 2 3 4 5的链接时
分别在当前页加上指定的数字即可
"<a href='showPage.php?page=".($currentPage+1)."'>1</a>" .
"<a href='showPage.php?page=".($currentPage+2)."'>2</a>" .
"<a href='showPage.php?page=".($currentPage+3)."'>3</a>" .
"<a href='showPage.php?page=".($currentPage+4)."'>4</a>" .
"<a href='showPage.php?page=".($currentPage+5)."'>5</a>"
Page = CLng(Request("Page"))
If Page < 1 Then Page = 1
If Page > rs.PageCount Then Page = rs.PageCount
if not(rs.bof and rs.eof) then rs.AbsolutePage = Page
%><center>
<TABLE width=574 border=0 cellPadding=3 cellspacing="1" bordercolor="#999999">
<TBODY>
<TR>
<TD align=middle width=185 background="../images/search_09.gif"
height=32><strong>餐馆名</strong></TD>
<TD align=middle width=101 background="../images/search_09.gif"
height=32><strong>地区商圈</strong></TD>
<TD align=middle width=119 background="../images/search_09.gif"
height=32><strong>菜系名称</strong></TD>
<TD align=middle width=59 background="../images/search_09.gif"
height=32><strong>人均</strong></TD>
<TD width="74"
height=32 align=middle background="../images/search_09.gif"><strong>综合指数</strong></TD>
</TR>
<%if not(rs.bof and rs.eof) then
k=1
do while not rs.eof and k<=rs.pagesize%>
<TR bgColor=#ffffff>
<TD vAlign=top height="24"><a href="infor.asp?id=<%=rs("id")%>" target="_blank" class="bb"><%=rs("store_name")%></a></TD>
<TD vAlign=top>
<%
sql1="select smallarea_name from smallarea where id="&rs("smallarea_id")&""
set rs1=server.CreateObject("adodb.recordset")
rs1.open sql1,conn,1,1
if not(rs1.bof and rs1.eof) then
response.write rs1("smallarea_name")
end if
%></TD>
<TD vAlign=top><%
if rs("vegetables")="" then
response.write "其它"
else
response.write rs("vegetables")
end if
%></TD>
<TD vAlign=top>¥<%=rs("con_level")%></TD>
<TD vAlign=top>
<%if rs("rec_num")<>0 then
if rs("rec_num")<=10 then k=1
if rs("rec_num")<=20 and rs("rec_num")>10 then k=2
if rs("rec_num")<=30 and rs("rec_num")>20 then k=3
if rs("rec_num")<=40 and rs("rec_num")>30 then k=4
if rs("rec_num")<=50 and rs("rec_num")>40 then k=5
for i=1 to k%><IMG src="../images/left_top10_star.gif" vspace=3><%next
else%><IMG src="../images/left_top10_star.gif" vspace=3><%end if%>
</TD></TR>
<%i=i+1
k=k+1
rs.movenext
loop
else%>
<TR align="center">
<td colspan="5"><font color="#990000"><strong>暂无企业!!!</strong></font></td>
</tr>
<%end if%>
</TBODY>
</TABLE>
<%if not(rs.bof and rs.eof) then%>
<TABLE border=0 cellPadding=0 cellSpacing=0 height=1 width="575">
<TR>
<TD height=24 align="right"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="94%" align="right" bgcolor="#ffe38c">共找到<font color=red><%=rs.recordcount%></font>家企业 共<font color=red><%=rs.pagecount%></font>页 当前第<font color=red><%=page%></font>页
<%If Page <> 1 Then ' 如果不是位于第一页%>
<font size="2"><a href="seach_web.asp?page=1&<%=STR%>" target="_parent" class="bb">首 页</a>
<a href="seach_web.asp?page=<%=(Page-1)%>&<%=STR%>" target="_parent" class="bb">上一页</a>
<%End If
If Page <> rs.PageCount Then ' 如果不是位于最后一页
%>
<a href="seach_web.asp?page=<%=(Page+1)%>&<%=STR%>" target="_parent" class="bb">下一页</a>
<a href="seach_web.asp?page=<%=rs.PageCount%>&<%=STR%>" target="_parent" class="bb">最末页</a>
<%End If%>
跳转到第<span class="white">:</span></td>
<td width="3%" align="center" valign="middle" bgcolor="#ffe38c">
<form action="seach_web.asp" name="form1" target="_parent">
<select name="page" style="width:38px" onchange="javascript:submit()">
<option value=<%=page%>><%=page%></option>
<%for ipage=1 to rs.pagecount
if ipage<>page then%>
<option value=<%=ipage%>><%=ipage%></option>
<%end if%>
<%next%>
</select>
</td>
<%STR="bigarea="&clng(request("bigarea"))&"&smallarea="&request("smallarea")&"&perfee="&clng(request("perfee"))&"&dishsystem="&trim(request("dishsystem"))&"&types="&clng(request("types"))&"&actives="&trim(request("actives"))&"&keyword="&trim(request("keyword"))&""%><input name="bigarea" type="hidden" value=<%=clng(request("bigarea"))%>>
<input name="smallarea" type="hidden" value=<%=request("smallarea")%>>
<input name="perfee" type="hidden" value=<%=clng(request("perfee"))%>>
<input name="dishsystem" type="hidden" value=<%=trim(request("dishsystem"))%>>
<input name="types" type="hidden" value=<%=clng(request("types"))%>>
<input name="actives" type="hidden" value=<%=trim(request("actives"))%>>
<input name="keyword" type="hidden" value=<%=trim(request("keyword"))%>>
</form>
<td width="3%" align="right" bgcolor="#ffe38c">页 </td>
</tr>
</table>
</TD>
</TR>
</TABLE>
<%end if%>
这是我直接从页面的粘下来的,作一下修改就OK了
// 分页导航链接函数,自动判断当前页,递增输出10个页码
function cutpage_nav()
{
//引入参数
global $page_size, $page, $page_count, $boardid;
//至首页
if (($page <> 1) && ($page_count > $page_size))
{
echo "<a href=" . $PHP_SELF . "?boardid=$boardid&page=1>«</a> ";
}
// 总页不大于10
if ($page_count <= 10)
{
for ($i = 1; $i <= $page_count; $i++)
{
if ($i != $page)
{
echo "<a href=" . $PHP_SELF . "?boardid=$boardid&page=$i>$i</a> ";
}
else
{
echo "$i ";
}
}
}
//总页大于10
else
{
$a = $page; //定义初始循环变量
if (($page_count - $page) > 9)
{
$a = $page;
}
else
{
$a = ($page_count - 9);
} $b = $page + 9; //定义溢出循环变量
if ($b < $page_count)
{
$b = $page + 9;
}
else
{
$b = $page_count;
}
for ($i = $a; $i <= $b; $i++)
{
if ($i != $page)
{
echo "<a href=" . $PHP_SELF . "?boardid=$boardid&page=$i>$i</a> ";
}
else
{
echo "$i ";
}
}
}
//至末页
if (($page != $page_count) && ($page_count > $page_size))
{
echo "<a href=" . $PHP_SELF . "?boardid=$boardid&page=$page_count>»</a> ";
}
}