Display function of news management system developed with PHP

As mentioned in the previous section, after we complete the addition, we jump to the display page. Let’s look at the html code of the following display page:

        
ID 标题 内容 时间 操作
1 明天过后 大家好 15-6-28 修改 删除
首页 上一页 下一页 末页

First of all, we also connect to the database

header(" Content-type: text/html; charset=utf-8");//Set encoding
$con =@mysql_connect("localhost","root","root") or die("Database connection failed") ;
mysql_select_db('news') or die("The specified database cannot be opened");
mysql_query("set names utf8");//Set the character set of the database

Then we Take out the data and do paging

//Paging function
$page = isset($_GET['page'])?intval($_GET['page']):1;//Set the current page number, if not set to 1
$num=1;//
$sql="select * from new";
$result=mysql_query($sql);
$total=mysql_num_rows( $result);//Query the total number of data
$pagenum=ceil($total/$num);//Get the total number of pages
//If the incoming page parameter apge is greater than the total number of pages pagenum, the error message is displayed
if($page>$pagenum || $page == 0){
echo "";
exit;
}
$offset=($page-1)*$num;
/* Get the value offset of the first parameter of limit, if The first page is (1-1)*10=0, and the second page is (2-1)*10=10. (Number of pages passed in - 1) * The data of each page gets the value of the first parameter of limit */
$sql="select * from new order by id desc limit $offset,$num ";
$info=mysql_query($sql); //Get the data to be displayed for the corresponding page number
if($info && mysql_num_rows($info)){
while($row=mysql_fetch_assoc($info)){
$data[]=$row;
##









if(!empty($data)){
foreach($data as $row){
?>








}
}
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pagenum;

?>


using : page=">Next page
;Last page
;

##

Continuing Learning
||
$pagenum || $page == 0){ echo ""; exit; } $offset=($page-1)*$num; /* 获取limit的第一个参数的值 offset ,假如第一页则为(1-1)*10=0,第二页为(2-1)*10=10。 (传入的页数-1) * 每页的数据 得到limit第一个参数的值*/ $sql="select * from new order by id desc limit $offset,$num "; $info=mysql_query($sql); //获取相应页数所需要显示的数据 if($info && mysql_num_rows($info)){ while($row=mysql_fetch_assoc($info)){ $data[]=$row; } }else{ $data=array(); } ?>
ID标题内容时间操作

修改
删除
ID 标题 内容 时间 操作
修改 删除
首页 上一页 下一页 末页

submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!