SelectLimit($sql,$numrows=-1,$offset=-1,$inputarr=false) Returns a recordset if successful. Returns false otherwise. Performs a select statement, simulating PostgreSQL's SELECT statement, LIMIT $numrows OFFSET $offset clause.In PostgreSQL, SELECT * FROM TABLE LIMIT 3 will return the first 3 records only. The equivalent is $connection->SelectLimit('SELECT * FROM TABLE',3). This functionality is simulated for databases that do not possess this feature.And SELECT * FROM TABLE LIMIT 3 OFFSET 2 will return records 3, 4 and 5 (eg. after record 2, return 3 rows). The equivalent in ADOdb is $connection->SelectLimit('SELECT * FROM TABLE',3,2).Note that this is the opposite of MySQL's LIMIT clause. You can also set $connection->SelectLimit('SELECT * FROM TABLE',-1,10) to get rows 11 to the last row.The last parameter $inputarr is for databases that support variable binding such as Oracle oci8. This substantially reduces SQL compilation overhead. Below is an Oracle example: $conn->SelectLimit("SELECT * FROM TABLE WHERE COND=:val", 100,-1,array('val'=> $val));; The oci8po driver (oracle portable driver) uses the more standard bind variable of ?: $conn->SelectLimit("SELECT * FROM TABLE WHERE COND=?", 100,-1,array('val'=> $val)); Ron Wilson reports that SelectLimit does not work with UNIONs. *********adodb 的 SelectLimit 方法很好的解决了分页数据的提取问题
Returns a recordset if successful. Returns false otherwise. Performs a select statement, simulating PostgreSQL's SELECT statement, LIMIT $numrows OFFSET $offset clause.In PostgreSQL, SELECT * FROM TABLE LIMIT 3 will return the first 3 records only. The equivalent is $connection->SelectLimit('SELECT * FROM TABLE',3). This functionality is simulated for databases that do not possess this feature.And SELECT * FROM TABLE LIMIT 3 OFFSET 2 will return records 3, 4 and 5 (eg. after record 2, return 3 rows). The equivalent in ADOdb is $connection->SelectLimit('SELECT * FROM TABLE',3,2).Note that this is the opposite of MySQL's LIMIT clause. You can also set $connection->SelectLimit('SELECT * FROM TABLE',-1,10) to get rows 11 to the last row.The last parameter $inputarr is for databases that support variable binding such as Oracle oci8. This substantially reduces SQL compilation overhead. Below is an Oracle example: $conn->SelectLimit("SELECT * FROM TABLE WHERE COND=:val", 100,-1,array('val'=> $val));; The oci8po driver (oracle portable driver) uses the more standard bind variable of ?: $conn->SelectLimit("SELECT * FROM TABLE WHERE COND=?", 100,-1,array('val'=> $val)); Ron Wilson reports that SelectLimit does not work with UNIONs. *********adodb 的 SelectLimit 方法很好的解决了分页数据的提取问题
试一下,谢谢
大家继续,谢谢!!!
使用selectlimit()不是很理想,我能想到的方法是:先取得总记录数,然后根据分页条数计算总页数,然后根据你翻页的页码确定你下一页的开始和结束记录数。这要读多遍数据库。还有没有其他的方法?
使用selectlimit()的方法。如果各位还有更好的ADODB方法,请继续。
以下是代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body bgcolor="#FFFFFF" topmargin="0" leftmargin="0">
<?PHP
function LastNextPage($pagecount,$page,$table_style,$font_style){
//生成上一页下一页链接 global $QUERY_STRING,$HTTP_HOST,$SCRIPT_NAME;
$action="http://$HTTP_HOST".$SCRIPT_NAME;
if($QUERY_STRING!=""){
$query = explode("&",$QUERY_STRING);
while(list($index, $value) = each($query)) {
$a = explode("=",$value);
if(strcmp(strtolower($a[0]),"page")!=0){
$temp .= $a[0]."=".$a[1]."&";
}
}
}else{
$temp = "";
} print("<table " . $table_style . ">\n");
print("<form method=get onsubmit=\"document.location ='" . $action . "?" . $temp . "page='+ this.page.value;return false;\"><tr>\n");
print("<td align=right>\n");
print($font_style ."\n");
if($page<=1){
print ("[第一页] \n");
print ("[上一页] \n");
}else{
print("[<a href=" . $action . "?" . $temp . "page=1>第一页</a>] \n");
print("[<a href=" . $action . "?" . $temp . "page=" . ($page-1) . ">上一页</a>]\n");
} if($page>=$pagecount){
print ("[下一页] \n");
print ("[最后一页]\n");
}else{
print("[<a href=" . $action . "?" . $temp . "page=" . ($page+1) . ">下一页</a>] \n");
print("[<a href=" . $action . "?" . $temp . "page=" . $pagecount . ">最后一页</a>]\n");
}
print(" 第" . "<input tyep=text name=page maxlength=5 size=2 value=" . $page . ">" . "页\n<input type=submit style=\"font-size: 7pt\" value=GO>\n");
print(" 共 " . $pagecount . " 页\n");
print("</td>\n");
print("</tr></form>\n");
print("</table>\n");
}include('../adodb/adodb.inc.php');
$db = &NewADOConnection('mysql');
$db->Connect('localhost','root','','DBNAME');
$table="tablename";$sql="select * from " . $table ;$db->SetFetchMode(ADODB_FETCH_ASSOC); // Return associative array
$rs = &$db->Execute($sql);
$pagesize=20; //每页记录条数$result_num=$rs->RecordCount();if($result_num<=0){
if($search==""){
$word="目前还没有记录!";
}else{
$word="没有查到符合条件的记录!";
}
}else{ $maxpage=ceil($result_num/$pagesize); if(is_long($page) or $page==""){
$page=1;
}else{
$page=(int)($page);
}
if($page<1){
$page=1;
}else if( $page>$maxpage){
$page=$maxpage;
}
$recordSet = &$db->SelectLimit($sql,$pagesize,$pagesize*($page-1));
$n=1;
}
?><table align=center>
<?
//while($row = mysql_fetch_array($result)){
while (!$recordSet->EOF) {
//print $recordSet->fields[0].' '.$recordSet->fields[1].'<BR>';
?>
<tr bgcolor=#EEF8FD>
<td align=center><? print($recordSet->fields[0]); ?></td>
<td align=center><? print($recordSet->fields[1]); ?></td>
<td align=center><? print($recordSet->fields[2]); ?></td>
<td align=center><a href='bianji.php?id=<?print($recordSet->fields[0]);?>'>编辑</a></td>
</tr>
<?
$recordSet->MoveNext();
$n++;if($n > $pagesize) break;
}
?>
</table>
<? LastNextPage($maxpage,$page,"width=100% ","<p align=center class=font2>"); ?>
<?
$recordSet->Close(); # 选择性执行
$db->Close(); # 选择性执行
?>
</body>
</html>