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= odbc_result( $cur, 1 );// 抓取 "id" 欄位的資料
$name= odbc_result( $cur, 2 );// 抓取 "name"欄位的資料
$page=$_GET["page"];//判断一下$page是否为数字,不是数字将它设置为1
$psize=2;//设置页面大小
$trecord=5;
$tpage=Ceil($trecord/$psize);
//for($i=1;$i<=$tpage;$i++){
//if($i==$page){
//echo $i;
//echo "<tr><td>$id</td><td>$name</td></tr>\n";
//}else{
echo "<tr><td>".$id."</td><td>".$name."</td></tr>";
//}
//}
//echo "<a href=\"网址?page=".($page+1)."&其它参数\">Next</a> ";
//echo "- Pages: $page/$tpage Records: ".$page*$psize."/$trecord";
}
echo "<tr><td colspan=2>共 $num_row 人 </td></tr></table>";
odbc_close( $cnx);
//输出分页导航条代码:
echo $pagenav;

解决方案 »

  1.   

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="40"><input name="btnadd" type="button" value="add"  onClick="showhidden('block')"></td>
    <td><?php echo PageString($myPageSize,$myTotalRecord,$myPageNums,$myPageUrl)?></td>
      </tr>
    </table><br>
    <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#666666">
      <tr align="center" valign="middle" bgcolor="#FFFFFF"> 
        <td height="25"><strong>ID</strong></td>
        <td height="25"><strong>Name</strong></td>
        <td height="25"><strong>Email</strong></td>
        <td height="25"><strong>Content</strong></td>
        <td height="25"><strong>Dtime</strong></td>
        <td height="25"><strong>Reply</strong></td>
        <td height="25"><strong>ReTime</strong></td>
      </tr>
      <?php
    for ($i=$myPageSize*($myPageNums-1);$i<$myPageNums*$myPageSize;$i++)
      {
    if($i==$myTotalRecord)
    break;
    ?>
        <tr bgcolor="##FFFFFF"> 
          <td height="20"><?php echo $rs->fields["ID"]->value;?></td>
          <td><?php echo $rs->fields["Name"]->value;?></td>
          <td><?php echo $rs->fields["Email"]->value;?></td>
          <td><?php echo $rs->fields["Content"]->value;?></td>
          <td><?php echo $rs->fields["Dtime"]->value;?></td>
          <td><?php echo $rs->fields["Reply"]->value;?></td>
          <td><?php echo $rs->fields["ReTime"]->value;?></td>
        </tr>
      <?php
      $rs->movenext();
      } 
      ?> 
    </table>
      

  2.   

    <?php
    $myPageSize=3;
    $sql="select * from guestbook order by id desc";
    $rs = new COM('ADODB.recordset');   
    $rs->open($sql,$conn,1,1);$rs->pagesize=$myPageSize;
    $myTotalRecord=$rs->recordcount;
    $myPageNums=$_GET["Page"];if ($myPageNums == "" && !is_int($myPageNums)){
    $myPageNums = 1;
    }
    else{
    $myPageNums = (int)($myPageNums);
    }
    if (!$rs->eof){
    $rs->Absolutepage=$myPageNums;
    }
    $myPageUrl=$PHP_SELF;
    ?>