我的翻页全程序<?
$PageSize = 20;//每页显示记录
if($TotalRecord==0)
$TotalRecord=1;
$PageCount=intval($TotalRecord/$PageSize);
if ($TotalRecord%$PageSize)
$PageCount++;
if ($page<>""){
$CurrentPage=intval($page);
if ($CurrentPage<1) $CurrentPage=1;
if ($CurrentPage>$PageCount)$CurrentPage=$PageCount; }
else{
$CurrentPage=1;}?>
<br><table width="778" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="23%" height="75" valign="top" bgcolor="#BDD3E7">
<? include "left.php3"?>
</td>
<td width="77%" valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#BDD3E7">
<table width="100%" height="76" border="0" cellpadding="1" cellspacing="1">
<tr bgcolor="#FFFFFF">
<td height="24"> <div align="center" style="font:14px"><strong>搜索结果</strong></div></td>
</tr>
<?
$i=1;
$offset=($CurrentPage-1)*$PageSize;
//取记录
mysql_data_seek($result,$offset);
//$result=mysql_query("select top $PageSize * from Card order by id desc ");
while($result and $row=mysql_fetch_array($result)){
?>
<tr bgcolor="#FFFFFF">
<td height="24"><? echo "<a href='ViewNews.php3?Id=".$row["Id"]."' target=_blank>".$row["Title"]."</a>";?></td>
</tr> <?
$i++;
if ($i>$PageSize){break;}
}?>
<tr bgcolor="#FFFFFF">
<td height="24"> <? $url="ClassId=".$ClassId;
showpage($CurrentPage,$PageCount,$url);?></td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
</table>
<?function showpage($CurrentPage,$PageCount,$url){
?>
<table width="500" border="0" align="center">
<form name="form1" method="post" action="Search.php3?<? echo $url?>"> <tr>
<td width="25%"><?echo "当前第".$CurrentPage."页,共".$PageCount."页"?></td>
<td width="11%">
<div align="center">
<?
if($CurrentPage>1){
echo "<a href=".$PHP_SELF."?page=1&".$url.">首页</a>";}
else{echo "首页";}
?>
</div>
</td>
<td width="14%">
<div align="center"><? if($CurrentPage>1){
echo "<a href=".$PHP_SELP."?page=".($CurrentPage-1)."&".$url.">前一页</a>";}
else{echo "前一页";}
?></div>
</td>
<td width="15%">
<div align="center"><? if($CurrentPage<$PageCount){
echo "<a href=".$PHP_SELP."?page=".($CurrentPage+1)."&".$url.">后一页</a>";}
else{echo "后一页";}
?></div>
</td>
<td width="7%">
<div align="center"><? if($CurrentPage<$PageCount){
echo "<a href=".$PHP_SELP."?page=".$PageCount."&".$url.">末页</a>";}
else{echo "末页";}
?></div>
</td>
<td width="5%">
<div align="center"></div>
</td>
<td width="23%">
<p align="center">转到:
<select name="page">
<?for ($i=1;$i<=$PageCount;$i++){
if($CurrentPage==$i)
{$check="selected";}
else{$check="";};
echo "<option value='".$i."' ".$check.">".$i."</option>";
}?>
</select>
<input type="submit" name="Submit" value="Go">
</p>
</td>
</tr></form>
</table>
$PageSize = 20;//每页显示记录
if($TotalRecord==0)
$TotalRecord=1;
$PageCount=intval($TotalRecord/$PageSize);
if ($TotalRecord%$PageSize)
$PageCount++;
if ($page<>""){
$CurrentPage=intval($page);
if ($CurrentPage<1) $CurrentPage=1;
if ($CurrentPage>$PageCount)$CurrentPage=$PageCount; }
else{
$CurrentPage=1;}?>
<br><table width="778" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="23%" height="75" valign="top" bgcolor="#BDD3E7">
<? include "left.php3"?>
</td>
<td width="77%" valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#BDD3E7">
<table width="100%" height="76" border="0" cellpadding="1" cellspacing="1">
<tr bgcolor="#FFFFFF">
<td height="24"> <div align="center" style="font:14px"><strong>搜索结果</strong></div></td>
</tr>
<?
$i=1;
$offset=($CurrentPage-1)*$PageSize;
//取记录
mysql_data_seek($result,$offset);
//$result=mysql_query("select top $PageSize * from Card order by id desc ");
while($result and $row=mysql_fetch_array($result)){
?>
<tr bgcolor="#FFFFFF">
<td height="24"><? echo "<a href='ViewNews.php3?Id=".$row["Id"]."' target=_blank>".$row["Title"]."</a>";?></td>
</tr> <?
$i++;
if ($i>$PageSize){break;}
}?>
<tr bgcolor="#FFFFFF">
<td height="24"> <? $url="ClassId=".$ClassId;
showpage($CurrentPage,$PageCount,$url);?></td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
</table>
<?function showpage($CurrentPage,$PageCount,$url){
?>
<table width="500" border="0" align="center">
<form name="form1" method="post" action="Search.php3?<? echo $url?>"> <tr>
<td width="25%"><?echo "当前第".$CurrentPage."页,共".$PageCount."页"?></td>
<td width="11%">
<div align="center">
<?
if($CurrentPage>1){
echo "<a href=".$PHP_SELF."?page=1&".$url.">首页</a>";}
else{echo "首页";}
?>
</div>
</td>
<td width="14%">
<div align="center"><? if($CurrentPage>1){
echo "<a href=".$PHP_SELP."?page=".($CurrentPage-1)."&".$url.">前一页</a>";}
else{echo "前一页";}
?></div>
</td>
<td width="15%">
<div align="center"><? if($CurrentPage<$PageCount){
echo "<a href=".$PHP_SELP."?page=".($CurrentPage+1)."&".$url.">后一页</a>";}
else{echo "后一页";}
?></div>
</td>
<td width="7%">
<div align="center"><? if($CurrentPage<$PageCount){
echo "<a href=".$PHP_SELP."?page=".$PageCount."&".$url.">末页</a>";}
else{echo "末页";}
?></div>
</td>
<td width="5%">
<div align="center"></div>
</td>
<td width="23%">
<p align="center">转到:
<select name="page">
<?for ($i=1;$i<=$PageCount;$i++){
if($CurrentPage==$i)
{$check="selected";}
else{$check="";};
echo "<option value='".$i."' ".$check.">".$i."</option>";
}?>
</select>
<input type="submit" name="Submit" value="Go">
</p>
</td>
</tr></form>
</table>
解决方案 »
- 第一次用CI框架写MODEL层
- 一个最简单phpExcel导出的例子,麻烦指点一下?
- Mysql的Handler_read_rnd_next值达到800G,怎么回事?
- 取值
- 随机取固定数值内的任意数字
- fsockopen打开错误
- 为什么本地测试用Localhost可以用127.0.0.1却不行
- 用Image_Graph在liunx下输出汉字的问题
- 求php 连接 mysql数据库代码。
- 迷惑,为什么我做的简体转繁体的php程序一定选择ie上的查看=》编码=》繁体,才能看到繁体呢
- 有个域名查询的程序,老出同样的问题,请指教!!在线等!!
- 有一个文件,共有四行内容如下,行与行之间是用\r来换行的,现在我想得到第三行的数据内容,应该如何做呢
分页函数
<%
sub pagination(pagename,pageno)
response.write "<table border=0 align=center>"
response.write "<tr alingn=right>"
response.write "<td>"
if pageno>1 then
response.write "<a href='"&pagename&"?page=1'><font size=2>第一页</a>"
else
response.write "<font size=2>第一页</font>"
end if
response.write "</td>"
response.write "<td>"
if pageno<rs.pageCount then
response.write "<a href='"&pagename&"?page="&pageno+1&"'><font size=2>下一页</font></a>"
else
response.write "<font size=2>下一页</font>"
end if
response.write "</td>"
response.write "<td>"
if pageno>1 then
response.write "<a href='"&pagename&"?page="&pageno-1&"'><font size=2>前一页</font></a>"
else
response.write "<font size=2>前一页</font>"
end if
response.write "</td>"
response.write "<td>"
if pageno<rs.pageCount then
response.write "<a href='"&pagename&"?page="&rs.pageCount&"'><font size=2>最后一页</font></a>"
else
response.write "<font size=2>最后一页</font>"
end if
response.write "</td>"
response.write "<td>"
response.write "<font size=2>页次:</font>"&pageno&"/"&rs.pageCount&"<font size=2>页共</font>"&rs.recordcount&"<font size=2>条记录</font>"
response.write "</td>"
response.write "</tr>"
response.write "</table>"
end sub
%>·······································
应用页<!-- #Include file="../inc/pageno.asp" --><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<link href="../inc/style.inc" rel="stylesheet" type="text/css">
</head>
<%
'pageno=1
fpath=Server.MapPath("../database/rescource.mdb")
set conn=Server.CreateObject("adodb.connection")
conn.open "Driver={Microsoft Access Driver (*.mdb)};dbq="&fpath
set rs=server.CreateObject("ADODB.recordset")
sql="select * from Inform"
rs.open sql,conn,1,3pagename="show.asp"
rs.pagesize=5
if isempty(request("page")) then
pageno=1
elseif cint(request("page"))<1 then
pageno=1
elseif cint(request("page"))>rs.pageCount then
pageno=rs.pageCount
else
pageno=cint(request("page"))
end if
rs.AbsolutePage=pageno
%>
<body>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td colspan="5" valign="top"><hr width="100%"></td>
</tr>
<%
j=0
while (not rs.eof) and j<rs.pagesize
flagcolor= not (flagcolor)
if (flagcolor) then
classtype = "tr3"
else
classtype = "tr1"
end if
%>
<tr class="<%=classtype%>">
<td width="4%" valign="top"><div align="center"><img src="../images/biao1.gif" width="15" height="13"></div></td>
<td valign="middle">
<% =rs.fields(1).value %></td>
<td width="6%" valign="middle"><div align="center"><a href="Newsadd.asp">添加</a></div></td>
<td width="6%"><div align="center"><a href="modify.asp?id=<% =rs("id") %>">修改</a></div></td>
<td width="6%"><div align="center"><a href="delete.asp?id=<% =rs("id") %>" onClick="return confirm('确定删除吗?');">删除</a></div></td>
<tr>
<%
rs.movenext
j=j+1
wend
%>
<td colspan="5" valign="top"><hr></td>
</tr>
</table>
<% call pagination(pagename,pageno) %>
<%
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
</body>
</html>
function multi($num, $perpage, $curr_page, $mpurl) {
$multipage = '';
if($num > $perpage) {
$page = 5;
$offset = 2; $pages = ceil($num / $perpage);
$from = $curr_page - $offset;
$to = $curr_page + $page - $offset - 1;
if($page > $pages) {
$from = 1;
$to = $pages;
} else {
if($from < 1) {
$to = $curr_page + 1 - $from;
$from = 1;
if(($to - $from) < $page && ($to - $from) < $pages) {
$to = $page;
}
} elseif($to > $pages) {
$from = $curr_page - $pages + $to;
$to = $pages;
if(($to - $from) < $page && ($to - $from) < $pages) {
$from = $pages - $page + 1;
}
}
}
$multipage .= "<a href=\"$mpurl&page=1\"><<</a> ";
for($i = $from; $i <= $to; $i++) {
if($i != $curr_page) {
$multipage .= "<a href=\"$mpurl&page=$i\">[$i]</a> ";
} else {
$multipage .= '<u><b>['.$i.']</b></u> ';
}
}
$multipage .= $pages > $page ? " ... <a href=\"$mpurl&page=$pages\"> [$pages] >></a>" : " <a href=\"$mpurl&page=$pages\">>></a>";
}
return $multipage;
}
<?php
if ( isset($_GET['page']) )
{
$page=$_GET['page'];
}
else
{
$page=0;
}
$pagelist=10;
$d_list_db=$page*$pagelist;
if (isset($_GET['title']))
{
$sql="select * from homepage_bj where home_url like '%".$_GET['title']."%' order by id desc limit $d_list_db,$pagelist";
}
else
{
$sql="select homepage_bj.*,users.password from homepage_bj inner join users on homepage_bj.username=users.username order by id desc limit $d_list_db,$pagelist";
}
$result=mysql_query($sql,$conn);
$c_sql="select count(id) as countid from homepage_bj";
$c_result=mysql_query($c_sql,$conn);
$c_rs=mysql_fetch_assoc($c_result);
$countpage=(int)($c_rs["countid"]/$pagelist);
?><style type="text/css">
<!--
a {
font-size: 9pt;
color: #333333;
}
a:visited {
color: #666666;
}
a:hover {
color: #99CC00;
}
a:active {
color: #999900;
}
body,td,th {
font-size: 9pt;
}
-->
</style>
<form name="form1" method="get" action="?">
<div align="center">
<input name="title" type="text" id="title">
<input type="submit" name="Submit" value="提交">
</div>
</form>
<?php
if (mysql_num_rows($result)==0)
{
echo "错误!";
exit;
}
?><table width="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<?php
while ($rs = mysql_fetch_assoc($result))
{
?>
<tr>
<td bgcolor="#FFFFFF"><?php echo $rs["home_url"]?></td>
<td bgcolor="#FFFFFF"><?php echo $rs["password"]?></td>
</tr><?
}
?>
</table>
<div align="center"><br>
<?php
if ($page>0)
{
echo "<a href=?page=0>【第一页】</a>| <a href=?page=".($page-1).">【上一页】</a>| ";
}
else
{
echo "【第一页】|【上一页】| ";
}
if ($page<$countpage)
{
echo "<a href=?page=".($page+1).">【下一页】</a>| <a href=?page=".$countpage.">【末一页】</a>";
}
else
{
echo "【下一页】|【末一页】";
}
echo " 一共有数据".$c_rs["countid"]."条。当前显示".($page+1)."/".($countpage+1);
?>
</div>
2)printf("<td><font color='#green'><a href='addtype.php?usr=%s'>%s</a></font></td>",$data["foad"]);
这条语句有错误,修改为:
printf("<td><font color='#green'><a href='addtype.php?usr=%s'>%s</a></font></td>",$data["foad"],$data["foad"]);里面有两个"%s",后面应该由两个变量对应
3)修改
if ($offset!=0) {
print "<tr><td><center><a href=\"select.php?offset=$prevoffset\">前一页</a></td>";
}
增加$prevoffset=$offset-$limit;放在输出语句前,即:
if ($offset!=0) {
$prevoffset=$offset-$limit;
print "<tr><td><center><a href=\"select.php?offset=$prevoffset\">前一页</a></td>";
}
这里,你没有对$prevoffset变量赋值,所以前一页链接不正确。4)$result=mysql_query("SELECT nin.name,nin.type,bog.foad from nin left join bog on nin.id=bog.bogid where bog.bogname='$textfield2' or nin.name='$textfield17' LIMIT $offset, 5",$myconn);
修改为:
$result=mysql_query("SELECT nin.name,nin.type,bog.foad from nin left join bog on nin.id=bog.bogid where bog.bogname='$textfield2' or nin.name='$textfield17' LIMIT $offset, $limit",$myconn);将5用$limit变量替代,岂不更好。
但你的最后一页判断不正确,时间紧张,就不写了,抱歉!
<?php
$db = mysql_connect("localhost", "root","");
mysql_select_db("tt");
$sql = mysql_query("SELECT time,type,more,sky,book FROM dor" ,$db);
while ($data=mysql_fetch_array($sql))
{
printf("<tr bgcolor='#FFFFCC' ><td><font color='#teal' size='2'>%s</font></td>",$data["time"]);
printf("<td><font color='#00000' size='2'>%s</font></td>",$data["type"]);
printf("<td ><font color='#green' size='2'>%s</font></td>",$data["more"]);
printf("<td><font color='#blue' size='2'>%s</font></td>",$data["sky"]);
printf("<td><font color='#puchsia' size='2'>%s</font></td>",$data["book"]); }
?>
这些内容我都从数据库里显示出来了,就是不知道怎么样分页,不知道怎么样传值,
拜托大家了,不然。又有的批了