asp分页,请高手求救
我要实现的是每页10条数据,可是在数据库里一共有10页的数据.显示的时候下面下一页代替1,2,3,4,5来显示.
然后有6页的话出来一个NEXT按扭,按这个的时候把6页的数据显示出来并且把12345该为678910.
请高手帮忙.
补充:我要做一个,不是要帮你们看错误.
请给个代码好吗?
补充:我要做一个,不是要帮你们看错误.
请给个代码好吗?
答案:<%
class cls_page
private spageindex
private spagesize
private stblname
private sfldname
private sordertype
private sstrwhere
private sstrurl
private srs
private sconn
private stotal
private stotalpage
public property let pageindex(value)'当前页数
spageindex=value
end property
public property let pagesize(value)'每页记录数
spagesize=value
end property
public property let tablename(value)'表名
stblname=value
end property
public property let fieldname(value) '排序字段名
sfldname=value
end property
public property let ordertype(value)'排序方式
sordertype=value
end property
public property let strwhere(value)'sql参数
sstrwhere=value
end property
public property let strurl(value)'分页参数
sstrurl=value
end property
public property let strconn(value)'连接字符串
set sc
end property
public property get pagesize
pagesize=spagesize
end property
Private Sub Class_Initialize
spagesize=10
end sub
Private Sub Class_Terminate
end sub
private Function GetPageSql()'获得sql
Dim StrTemp,StrSql,StrOrder
If sOrderType = 0 Then
StrTemp = "> (Select Max([" & sFldName & "])"
StrOrder = " Order By [" & sFldName & "] Asc"
Else
StrTemp = "< (Select Min([" & sFldName & "])"
StrOrder = " Order By [" & sFldName & "] Desc"
End If
If sPageIndex = 1 Then
StrTemp = ""
If sStrWhere <> "" Then
Strtmp = " Where " & StrWhere
End If
StrSql = "Select Top " & sPageSize & " * From [" & sTblName & "]" & Strtmp & StrOrder
Else
StrSql = "Select Top " & sPageSize & " * From [" & sTblName & "] Where [" & sFldName & "]" & StrTemp & _
" From (Select Top " & (sPageIndex-1) * sPageSize & " [" & sFldName & "] From [" & sTblName & "]"
If sStrWhere <> "" Then
StrSql = StrSql & " Where " & sStrWhere
End If
StrSql = StrSql & StrOrder & ") As Tbltemp)"
If sStrWhere <> "" Then
StrSql = StrSql & " And " & sStrWhere
End If
StrSql = StrSql & StrOrder
End If
GetPageSql = StrSql
End Function
public property get getrs()'获得rs
set srs=server.CreateObject("adodb.recordset")
srs.open GetPageSql,sconn,1,1
set getrs=srs
end property
public sub listbar()'分页导航条
sql="select * from "&stblname&""
set rs=server.CreateObject("adodb.recordset")
rs.open sql,sconn,1,3
total=rs.recordcount
totalpage=rs.pagecount
rs.close
set rs=nothing
response.Write("共有纪录 <font color=red><b>"&total&"</b></font> 条 ")
response.Write("记录共 <font color=red><b>"&totalpage&"</b></font> 页 ")
response.Write("当前为第 <font color=red><b>"&spageindex&"</b></font>/"&totalpage&" 页 ")
If totalpage=1 Then
Response.write "·共有1页·"
End If
If Not spageindex=1 Then
Response.write "<a href=>Response.write "<a href=>Else
Response.write "首页 "
Response.write "前页 "
End If
If spageindex<>totalpage Then
Response.Write "<a href=>Response.Write "<a href=>Else
Response.Write "后页 "
Response.Write "尾页"
End If
response.Write(" 选择查看<select .location='?page='+this.options[selectedIndex].value+'&"&sstrurl&"'; name=select3>")
for ipage=1 to totalpage
response.write "<option value="&ipage
if ipage=cint(spageindex) then response.write " selected"
response.write ">"&ipage&"</option>"
next
response.Write("</select>页")
end sub
end class
%>这个控件就好直接去实现分页的,代码不好给你的!!
用GRILDVIEW 就好实现了<?php
include"config/conn1.php";
include"config/db_func.php";
// 导入两个数据库元件 END
// 取出留言数据并依发布时间递减排序的 SQL 语句
$SQLStr = "SELECT * FROM news ORDER BY ftime DESC";
$res = db_query($SQLStr); // 执行 SQL 命令
?>
<table width="750" border="0" align="center" cellpadding="0" cellspacing="1">
<?
if (db_num_rows($res)>0) // 若表中有数据
{
$num = db_num_rows($res); // 取得数据笔数
$check = $p+10; // 每页抓取 10 笔数据
// 呈现留言列表的字段内容 BEGIN
for ($i=0;$i<=$num;$i++) // 用来呈现多笔留言数据的循环
{
$row = db_fetch_array($res);
// 选取第 $p 笔到 $check 笔数据
if ($i>=$p && $i<$check)
{
// 利用是否被整除来判断字段的背景颜色
if ($i%2 == 0)
echo "<tr bgcolor='#DDDDDD'>";
else
echo "<tr>";
// 判断 m_title 字段内字符串值是否超过 15 字符
if (strlen($row['title'])>15)
{
echo "<td width='280'><a href=>echo substr($row['title'],0,30) . "...</a></td>";
}
else
{
echo "<td width='280'><a href=>echo $row['title'] . "</a></td>";
}
// 判断 m_content 字段内字符串值是否有包含 <br> 字符串
if (stristr($row['content'],"<br>"))
{
echo "<td width='300'><a href=>echo substr($row['content'], 0, 0 - strlen(strstr($row['content'],"<br>"))) . "...</a></td>";
}
else
{
echo "<td width='300'><a href=>echo $row['m_content'] . "</a></td>";
}
//echo "<td width='60' align='center'><a href=>
// 仅选取 m_time 字段内 16 个字符的数据
echo "<td width='130' align='center'>" . substr($row['ftime'],0,16) . "</td>";
echo "</tr>";
$j = $i+1;
}
}
// 呈现留言列表的字段内容 END
}
?>
</table>
<br>
<table width="406" border="0" align="center">
<tr>
<td align="center">
<!--- 将 p 值设为 0, 让模块从第一笔数据开始抓取 ---->
<a href=></td>
<td align="center">
<?
if ($p>9) // 判断是否有上一页
{
$last = (floor($j/10)*10)-10;
echo "<a href=>}
else
echo "上一页";
?>
</td>
<td align="center">
<?
if ($i>9 and $num>$check) // 判断是否有下一页
echo "<a href=>else
echo "下一页";
?>
</td>
<td align="center">
<?
if ($i>9) // 判断目前呈现的笔数之后是否还有页面
{
// 取得最后一页的第一笔数据
$final = floor($num/10)*10;
echo "<a href=>}
else
echo "最后一页";
?>
</td>
</tr>
</table>与jsp的类似,需要的话,我这有,可以给你如果你现在还没解决的话,我可以给你个控件,我们现在在用的分页控件,只要2句代码,改改属性就可以了,要的话加我QQ250023246
上一个:帮我看看这个asp文件哪里出错了谢谢
下一个:asp.net 连接access数据库出现insert into 语法错误