一个PHP+MSSQL分页的例子

5年以前  |  阅读数:830 次  |  编程语言:PHP 

<?
require "config.php";
dl("extensions/php_mssql70.dll");
if (!isset($page)) { $page=1; }
if ($page<=0) { $page=1; }
$db=mssql_connect($local,$user,$pass);
mssql_select_db($name,$db);
$query=mssql_query("select count() as date from news",$db);
$query=mssql_fetch_array($query);
$pages=ceil($query[0]/$userperpage);
if ($page>$pages) { $page=$pages;}
if ($query[0]<$userperpage) { $userperpage=$query[0]; }
$dangqian=($page-1)
$userperpage;
echo "News";
echo "\n";
echo "

\n";
echo "<table border=0 width=100% cellspacing=0 cellpadding=0 height=19\n";
echo "";
echo " \n";
echo "";
echo "

<font\n";
echo " color=#408080>新闻标题\n";
echo " <font\n";
echo " color=#408080>发表日期\n";
echo " <font\n";
echo " color=#408080>发表部门\n";
echo " <font\n";
echo " color=#408080>阅读\n";
echo " <font\n";
echo " color=#408080>图像\n";
echo " \n";
echo "\n";
echo "

\n";
echo "
\n";
echo "\n";
$db=mssql_connect($local,$user,$pass);
mssql_select_db($name,$db);
$query=mssql_query("select * from news order by date desc",$db);
$roro=mssql_num_rows($query);
if ($roro==0) {
echo "

<p align=\"center\"><font color=\"#FF0000\" size=\"2\"><marquee behavior=\"alternate\" border=\"0\" width=\"300\" height=\"16\" scrolldelay=\"70\">目前数据库中无任何记录!

";
exit;
}
mssql_data_seek($query,$dangqian);
$i=0;
while ($arr=mssql_fetch_array($query)) {
if ($i>=$userperpage) { break;}
echo "\n";
echo " \n";
$datee=date("Y-m-d",$arr[date]);
echo " \n";
echo " \n";
echo " \n";
echo " \n";
echo "\n";
$i++;
} //while
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "

<a href=\"readnews.php?id=$arr[date]\" target=\"_blank\">$arr[title]

$datee$arr[type]$arr[click]\n";
$arr[photo]=trim($arr[photo]);
if (($arr[photo]<>"") || (file_exists($arr[photo]))) {
echo "";
}
else { echo " "; }
echo "
\n";
if ($page<>1) {
echo "<a href=$PHP_SELF?page=1>首页\n";
}
if ($page>1) {
$upage=$page-1;
echo "<a href=$PHP_SELF?page=$upage>上一页\n";
}
for($y=1;$y<=$pages;$y++) {
echo "<a href=$PHP_SELF?page=$y>$y\n";
}
if ($page<$pages) {
$npage=$page+1;
echo "<a href=$PHP_SELF?page=$npage>下一页\n";
}
if ($page<>$pages) {
echo "<a href=$PHP_SELF?page=$pages>尾页\n";
}
echo "
\n";
echo "
\n";
?>

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例