用ODBC的分页显示

?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”State of Qatar; //总计总页数 $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); ?

盛开数据库连接已成为一种与数据库实行通讯的工业标准。PHP也提供了正规的接口,使得PHP能调用Access,SQL
SE索罗德VE哈弗等数据库。其荣辱与共函数是: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
rowState of Qatar从二个结出集中获取一行数据。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 =

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
($cnnnState of Qatar{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卡塔尔State of Qatar{$i++;};};$i=1;//显示记录while(odbc_fetch_row($cur)){echo
;if ($i == $show_num卡塔尔{//在不满页数时跳出程序break; };$i++;};
//关闭连接odbc_close($conn_id);?

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图