<?php
//分页的函数
function news($pageNum = 1, $pageSize = 5)
{
$array = array();
// $coon = mysqli_connect('rm-bp108931c0786t58eko.mysql.rds.aliyuncs.com','jjadmin','jj960820-COM','table_jjf');
$coon = mysqli_connect('localhost','root','96jj0820com','shuju');
mysqli_set_charset($coon, "utf8");
// limit为约束显示多少条信息,后面有两个参数,第一个为从第几个开始,第二个为长度
$rs = "select * from news limit " . (($pageNum - 1) * $pageSize) . "," . $pageSize ;
$r = mysqli_query($coon, $rs);
while ($obj = mysqli_fetch_object($r)) {
$array[] = $obj;
}
mysqli_close($coon,"table_jjf");
return $array;
}
//显示总页数的函数
function allNews()
{
// $coon = mysqli_connect('rm-bp108931c0786t58eko.mysql.rds.aliyuncs.com','jjadmin','jj960820-COM','table_jjf');
$coon = mysqli_connect('localhost','root','96jj0820com','shuju');
mysqli_set_charset($coon, "utf8");
$rs = "select count(*) num from news"; //可以显示出总页数
$r = mysqli_query($coon, $rs);
$obj = mysqli_fetch_object($r);
mysqli_close($coon,"table_jjf");
return $obj->num;
}
@$allNum = allNews();
@$pageSize = 5; //约定每页显示几条信息
@$pageNum = empty($_GET["pageNum"])?1:$_GET["pageNum"];
@$endPage = ceil($allNum/$pageSize); //总页数
@$array = news($pageNum,$pageSize);
?>
#
1。sql语句加上排序 你可以按时间排序或者按自增ID排序
2。没有看到你的网站模板 不能指导你将信息输出到页面上