<?
function Error_Handler( $msg, $cnx )
{
echo "$msg \n";
odbc_close( $cnx);
exit();
}
$cnx = odbc_connect( 'WebDB' , 'webuser', 'webpassword' );
if( ! $cnx ) {
Error_handler( "在 odbc_connect 有錯誤發生" , $cnx );
}
$cur= odbc_exec( $cnx, "select u_id,u_name,u_content from test" );
if( ! $cur ) {
Error_handler( "在 odbc_exec 有錯誤發生( 沒有指標傳回 ) " , $cnx );
}
echo "<table border=1><tr><th>编号</th><th>客户单位</th></tr>\n";$num_row=0;
// 取出成功傳回的資料
while( odbc_fetch_row( $cur ) )
{
$num_row++;
// 抓取 "id" 欄位的資料
$id= odbc_result( $cur, 1 );
// 抓取 "name"欄位的資料
$name= odbc_result( $cur, 2 );
echo "<tr><td>$id</td><td>$name</td></tr>\n";
}
echo "<tr><td colspan=2>共 $num_row 人 </td></tr></table>";
odbc_close( $cnx);
?>
以上代码,是从access数据库里读的记录,想实现分页的效果。
1,2,3,4。。
首页,前一页,后一页,未页
共多少页
function Error_Handler( $msg, $cnx )
{
echo "$msg \n";
odbc_close( $cnx);
exit();
}
$cnx = odbc_connect( 'WebDB' , 'webuser', 'webpassword' );
if( ! $cnx ) {
Error_handler( "在 odbc_connect 有錯誤發生" , $cnx );
}
$cur= odbc_exec( $cnx, "select u_id,u_name,u_content from test" );
if( ! $cur ) {
Error_handler( "在 odbc_exec 有錯誤發生( 沒有指標傳回 ) " , $cnx );
}
echo "<table border=1><tr><th>编号</th><th>客户单位</th></tr>\n";$num_row=0;
// 取出成功傳回的資料
while( odbc_fetch_row( $cur ) )
{
$num_row++;
// 抓取 "id" 欄位的資料
$id= odbc_result( $cur, 1 );
// 抓取 "name"欄位的資料
$name= odbc_result( $cur, 2 );
echo "<tr><td>$id</td><td>$name</td></tr>\n";
}
echo "<tr><td colspan=2>共 $num_row 人 </td></tr></table>";
odbc_close( $cnx);
?>
以上代码,是从access数据库里读的记录,想实现分页的效果。
1,2,3,4。。
首页,前一页,后一页,未页
共多少页
记录总数:$all_num
单页记录数:$per_num则当前的显示记录为:从($page-1)*$per_num到$page*$per_num间的记录
用个循环就可以了.
for($i=0;$i<$all_num;$i++)
{
if($i>=($page-1)*$per_num && $i<$page*$per_num)
{
//显示
}
}这是比较占资源的一种.呵呵..