澳门新葡萄京娱乐场用ODBC的分页显示

开放数据库连接已成为一种与数据库进行通信的工业标准。PHP也提供了标准的接口,使得PHP能调用Access,SQL
SERVER等数据库。其相关函数是:integer odbc_connect(string dsn, string
user, string password)连接到一个ODBC数据库源名字上。integer
odbc_exec(integer connection, string query)或 odbc_do(integer
connection, string query)在一个连接上执行查询。boolean
odbc_fetch_row(integer result, integer
row)从一个结果集中获取一行数据。Row参数是可选的,若为空缺,则返回下一个有效行。在结果集中不再剩余行时返回false。boolean
odbc_close(integer
connection)关闭一个数据库的连接。若在该连接上有打开的事务,则返回一个错误,而且连接不会被关闭。最后,还是看个分页的例子:?//设定每页显示条数$show_num
= 10;$spages = $pages;//避免$pages后期被改变//定义连接$dsn =
localhost;$user = sa;$password = ;//计算总记录数$rs_num = select
count(*) as id from bbs where zu=’0′ and lei=’.$lei.’;$conn_id =
odbc_connect($dsn,$user,$password);$rnum =

?php $pagesize = 3;//设置每页显示数目 //计算总记录数 $rs_num = “select
count(*) as id from table”; $rs_num = odbc_exec($conn_id,$rs_num);
$rs_num = odbc_result($rs_num,”id”); //计算总页数 $pagecount =
$rs_num / $pagesize; $pagecount1 = intval($pagecount);//将总页数取整
$compare = $pagecount – $pagecount1; switch ($compare){ case “0”:
$pagecount = $pagecount1;//总页数 break; default : $pagecount1++;
$pagecount = $pagecount1;//总页数 break; }; if ($pagecount ==
0)$pagecount++; $fpages = $pages-1; $bpages = $pages+1; ? table tr td
共?php echo $pagecount ?页 ?php if($pages != 1)echo “a
href=show.php3?pages=1”;?首页?php if($pages != 1)echo “/a”; ? ?php
if($pages != 1)echo “a href=show.php3?pages=”.$fpages.””; ?前页?php
if($pages != 1)echo “/a”; ? ?php if($pages != $pagecount)echo “a
href=show.php3?pages=”.$bpages.””; ?后页?php if($pages !=
$pagecount)echo “/a”; ? ?php if($pages != $pagecount)echo “a
href=show.php3?pages=”.$pagecount.””; ? 尾页?php if($pages !=
$pagecount)echo “/a”; ? /td /tr/table ?php $firstshow =
($pages-1)*$pagesize+1;//确定每页的第一条记录 //找出第一条记录的记录号
$query_string = “SELECT * FROM table Order By id DESC”; $query_string
= odbc_exec($conn_id,$query_string);
odbc_fetch_into($query_string,$firstshow,$idarea); $idsql =
$idarea[0]; //定位查找 if ($pages == $pagecount) { $rs = “SELECT *
FROM table where id = “.$idsql.” Order By id DESC”; }else{ $rs = “SELECT
Top “.$pagesize.” * FROM table where id = “.$idsql.” Order By id DESC”;
}; $rs = odbc_exec($conn_id,$rs); //显示记录
while(odbc_fetch_row($rs)){ }; ? ?php //关闭连接
odbc_close($conn_id); ?

odbc_exec($conn_id,$rs_num);while(odbc_fetch_row($rnum)){$total_rs

odbc_result($rnum,id);//将总记录数放入$total_rs变量}//计算与页有关的条数$nnn
= $total_rs / $show_num;//计算总页数$hnnn =
intval($nnn);//将总页数取整$cnnnn = $nnn – $hnnn;//计算所需总页数switch
($cnnn){case 0:$hnnn++;$nnn = $hnnn;//总页数break;default :$nnn =
$hnnn;//总页数break;};if ($nnn == 0)$nnn++;//计算页面改变所需的条件$fore
= $pages;$next = $pages;$fore -= 1;$next += 1;if ($fore 0) {echo
a首页/a;echo a前页/a;};if ($pages $nnn) {echo a后页/a;echo
a尾页/a;};echo 共.$nnn.页;$query_string = SELECT * FROM table where
condition order by you wanted order;$cur =
odbc_exec($conn_id,$query_string);//取到循环的顶部$cnum = ($pages-1)
* $show_num;//计算当前的记录游标的位置//空循环到显示记录游标处if
($cnum != 0){for
($i=0;$i=$cnum;odbc_fetch_row($cur)){$i++;};};$i=1;//显示记录while(odbc_fetch_row($cur)){echo
;if ($i == $show_num){//在不满页数时跳出程序break; };$i++;};
//关闭连接odbc_close($conn_id);?

发表评论

电子邮件地址不会被公开。 必填项已用*标注