一 代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>使用selectlimit函数查询数据</title> <style type="text/css"> <!-- body,td,th { font-size: 12px; } body { margin-left: 10px; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; } --> </style></head> <body> <?php include_once ('../adodb5/adodb.inc.php'); //载入(include)adodb.inc.php文件 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; //设置字段为结果集索引 $conn = ADONewConnection('mysql'); //建立连接 $conn -> PConnect('localhost','root','root','db_database14'); //连接数据库 $conn -> execute('set names gb2312'); //设置编码格式 $sql = 'select * from tb_object'; //要查询的SQL语句 $numrows = 2; //查找2条记录数 $offset = 1; //从第1条记录开始计算 $rst = $conn -> selectlimit($sql,$numrows,$offset) or die('execute error'); //调用selectlimit函数 while(!$rst -> EOF){ //如果没有错误,则配合wihle语句循环输出结果 echo $rst -> fields['bigclass'].'=>'.$rst -> fields['d_time'].' '; //输出查询结果 $rst -> movenext(); //指针下移 } $rst -> close(); //关闭连接 $conn -> close(); ?> </body> </html>
二 运行结果
建筑耗材=>2009-04-28 11:16:32 服装=>2008-02-25 14:56:21