本文實例為大家分享了PHP MSSQL可刷新分頁實例,具體內容如下
<?php /* '頁面說明: */ $link=mssql_connect("MYSQL2005","sa","123456") or die("db link error!".mssql_error()); mssql_select_db("edu_dzk",$link) or die("db open error!".mssql_error()); //mssql_query("set names 'utf8'"); $sqlstrcount="SELECT count(1) FROM reguser"; $page = $_GET["page"]; if(!is_numeric($page)){ $page="1"; } $pagesize="30"; //$sql=mysql_query($sqlstr); //$totalnum=mysql_num_rows($sql); $sql=mssql_query($sqlstrcount); list($totalnum)=mssql_fetch_row($sql); $pagecount=ceil($totalnum/$pagesize); $offset=($page-1)*$pagesize; $sqlstr="Select top ".($pagesize)." * from reguser where id not in (select top ".(($page-1)*$pagesize)." id from reguser order by id desc) order by id desc"; $sql=mssql_query($sqlstr); $result=""; while($result=mssql_fetch_array($sql)){ echo $result["id"].'<br>'; } showpageinfo2($totalnum,$pagecount,$page,"&z=".$z); mssql_Close($link); function showpageinfo2($totalnum,$pagecount,$page,$filster) { echo "共計: $totalnum 條記錄,共 $pagecount 頁,當前是第 $page 頁 "; if($page!=1) { echo "<a href=?page=1$filster>首頁</a> "; echo "<a href=?page=".($page-1)."$filster>上一頁</a> "; } if($page<$pagecount) { echo "<a href=?page=".($page+1)."$filster>下一頁</a> "; echo "<a href=?page=$pagecount$filster>尾頁</a> "; } } ?>
下面為大家分享了PHP+MSSQL通用分頁公式,供大家參考,具體內容如下
<?php //phpinfo(); //$conn=mssql_connect('192.168.0.3','app','web')or die (mssql_get_last_message()); //if($conn) //{ //?echo "success"; //}else{ //?echo "fail"; //} ?> <html> <head> <title>PHP分頁</title> </head> <body> <? $gPageSize= 10; //每頁顯示的記錄數 $hostname = "."; //MsSQL Server $dbuser = "sa"; //用戶名 $dbpasswd = ""; //密碼 //連接數據庫 $id = mssql_connect($hostname,$dbuser,$dbpasswd) or die("無法連接數據庫服務器!"); $db = mssql_select_db("phmis04",$id) or die("無法連接數據庫!"); //以xxx表為例,構建查詢字符串 $query = "select top 20 ag_mate,ag_color,ag_width,ag_mode,mi_name,convert(char,ag_date,23)as ag_date,ag_grid,au_name,ag_num from acco_grid join mate_info on ag_mate=mi_id join appl_unit on au_id=ag_unit;"; //執行查詢語句 $rresult = mssql_query($query) or die("無法執行SQL:$query"); //$page變量標示當前顯示的頁 if(!isset($page)) $page=1; if($page==0) $page=1; //得到當前查詢到的紀錄數 $nNumRows if(($nNumRows= mssql_num_rows($rresult))<=0) { echo "<p align=center>沒有紀錄"; exit; }; //得到最大頁碼數MaxPage $MaxPage = (int)ceil($nNumRows/$gPageSize); if((int)$page > $MaxPage) $page=$maxPage; ?> <table align="center" width="80%" border=0> <tr><td> <? echo "<font size=2>第 $page 頁,共 $MaxPage 頁</font>";?> </td><td></td></tr></table> <table align="center" width="80%" border="1" cellspacing="0" cellpadding="4" bordercolorlight="#CC9966" bgcolor="#00F2EE" bordercolordark="#FFFFFF" class="LZH"> <tr bgcolor="#F7F2ff" > <? //顯示表格頭 for($iCnt = 0; $iCnt < mssql_num_fields($rresult); $iCnt++) { echo "<td>".mssql_field_name($rresult,$iCnt)."</td>" ; } ?> </tr> <? //根據偏移量($page - 1)*$gPageSize,運用mssql_data_seek函數得到要顯示的頁面 if( mssql_data_seek($rresult,($page-1)*$gPageSize) ) { $i=0; //循環顯示當前紀錄集 for($i;$i<$gPageSize;$i++) { echo "<tr style=\"font-size:12px\">"; //得到當前紀錄,填充到數組$arr; $arr= mssql_fetch_row($rresult); if($arr) { //循環顯示當前紀錄的所有字段值 for($nOffSet = 0;$nOffSet < count($arr);$nOffSet++) { echo "<td>".$arr[$nOffSet]."</td>"; } } echo "</tr>"; } } ?> </table> <br> <hr size=1 width=80%> <div align=center > <? //首頁和上一頁的鏈接 if( $nNumRows>1 && $page>1) { $prevPage=$page-1; echo " <a href=".$PHP_SELF."?page=1>首頁</a> "; echo " <a href=".$PHP_SELF."?page=".$prevPage." >上一頁</a> "; } //下一頁和末頁的鏈接 if( $page>=1 && $page<$MaxPage) { $nextPage= $page+1; echo " <a href=".$PHP_SELF."?page=".$nextPage." >下一頁</a> "; echo " <a href=".$PHP_SELF."?page=".$MaxPage." >末頁</a> "; } ?> </div> </body> </html>
以上就是本文的全部內容,希望對大家學習php程序設計有所幫助。