MS SQL Server&PHP的分页原程序(ODBC版)
<br> $page = $arr_request['page'];<BR>$sql_type="exec p_comm_get_id_from_dict @main=\"理财博览\"";<BR>$conn = odbc_connect($odbc_name, $odbc_uid,$odbc_pwd) or die ("连接ODBC失败");<BR>$rst=odbc_exec($conn,$sql_type);<BR>$type=odbc_result($rst,1);<BR>odbc_free_result($rst);<BR>//$type=204;<BR><BR><BR>$sql = "select id,title,time from t_grlc_news where (datediff(d,time,getdate())<30) and type=$type order by time DESC";<BR>$record_num = "select count(*) as record_number from t_grlc_news where datediff(d,time,getdate())<30 and type=$type";<BR><BR>//定义每页记录数<BR>$pagesize =16;<BR><BR>//连接数据库求出总页数<BR>//$conn = odbc_connect($odbc_name, $odbc_uid,$odbc_pwd) or die ("连接ODBC失败");<BR>$rst = odbc_exec($conn,$record_num) or die("查询出错"); //执行取得记录总数SQL语句<BR>$record_count_num = odbc_result($rst,"record_number"); //取得记录总数,在这里也可以用$recordcount = odbc_result($rst,"record_number");<BR>odbc_free_result($rst); //释放资源<BR><BR>$page_count_num = ceil($record_count_num/$pagesize);<BR>//控制接收页数值的正确性<BR>if($page>$page_count_num)<BR>{<BR>$page = $page_count_num;<BR>}elseif($page<1)<BR>{<BR>$page = 1;<BR>}<BR><BR><BR>//以下输出内容<BR><BR><BR>$rst = odbc_exec($conn,$sql) or die("$sql查询出错"); //执行取得数据SQL语句<BR><BR>$fieldcount = odbc_num_fields($rst); //取得字段总数<BR>print '<table width=90% border="0" cellspacing="0" cellpadding="4" align=center>';<BR>$rowi = ($page-1)*$pagesize+1;<BR>for($i=0;$i<$pagesize;$i++){<BR>print '<tr>';<BR>if($rowi<=$record_count_num){<BR>odbc_fetch_into($rst,$rowi,&$row);<BR>if($i==0) print "<center><img src=\"../../images/grlc/e1.gif\" width=\"526\" height=\"36\"><br><hr width=100% color=#003399>";<BR>for($q=1;$q<=$fieldcount;$q++)<BR>{<BR>if(odbc_field_name($rst,$q)=='id')<BR>{<BR>$news_id=$row;<BR>}<BR>if (odbc_field_name($rst,$q)=='title')<BR>{<BR>print "<td width=80%><img src=\"../../images/grlc/star.gif\" width=\"8\" height=\"8\"><a href='lcbl_detail.php?id=$news_id' target=_blank><font color=#003399>" . $row . "</a></td>";<BR>}<BR>if(odbc_field_name($rst,$q)=='time')<BR>{<BR>print "<td width=20%>" .substr($row,0,10) . "</td>";<BR>}<BR>}<BR>$rowi = $rowi+1;<BR>}<BR>print '</tr>';<BR>}<BR><BR>print '</table>';<BR>odbc_free_result($rst); //释放资源<BR>odbc_close($conn); //关闭连接并释放资源<BR><BR>if ($page_count_num>1)<BR>{<BR>print "<form method=post action=\"$PHP_SELF?page=$pages\">";<BR>print "<table border=0 cellspacing=\"0\" cellpadding=\"0\"><tr bgcolor='#ffffff'>";<BR>if($page>1)<BR>{ //页码比0大,表示有数据<BR>print "<td width=80><a href=\"$PHP_SELF?page=1\"><font color=#EA005E>首页</font></a></td>";<BR>}<BR>else{<BR>print "<td width=80><font color=#EA005E>首页</font></td>";<BR>}<BR>if($page>1){<BR>$pages = $page - 1;<BR>print "<td width=80><a href=\"$PHP_SELF?page=$pages$sql_condition\"><font color=#EA005E>上页</font></a></td>";<BR>}<BR>else{<BR>print "<td width=80><font color=#EA005E>上页</font></td>";<BR>}<BR>if($page<$page_count_num){<BR>$pages = $page + 1;<BR>print "<td width=80><a href=\"$PHP_SELF?page=$pages$sql_condition\"><font color=#EA005E>下页</font></a></td>";}<BR>else{<BR>print "<td width=80><font color=#EA005E>下页</font></td>";<BR>}<BR>if($page<$page_count_num){<BR>print "<td width=80><a href=\"$PHP_SELF?page=$page_count_num\"><font color=#EA005E>尾页</font></a></td>";<BR>}<BR>else{<BR>print "<td width=80><font color=#EA005E>尾页</font></a></td>";<BR>}<BR>print "<td width=80><font color=#EA005E>页码($page/$page_count_num)</font></td>";<BR>print "<td width=80 align = center><input type=input size=3 name=page> <input type=submit value=go name=go></td>";<BR>print "</tr>";<BR>print "</table>";<BR>print "</form>";<BR>} <br><br>
页:
[1]