News release details pagination
梁温柔
梁温柔 2018-04-11 16:42:13
0
5
1311

Could you please tell me how to output the latest data on the front page of the front-end article list page in the pagination section, and then proceed in reverse order? If you click on the news page, the home page will display the latest data.

梁温柔
梁温柔

reply all(4)
梁温柔

I figured it out by myself, put this /* to get the value offset of the first parameter of limit, if the first page is (1-1)*10=0, the second page is (2-1)* 10=10. (Number of pages passed in - 1) * The data on each page gets the value of the first parameter of limit */
$sql="select * from article limit $offset,$num "; Just change it to the following one Ahaha

$sql="select * from article order by id desc limit $offset,$num ";

梁温柔

<?php
//Paging function
//Connect to database
require_once("connect.php");
$page = isset($_GET['page'])? intval($_GET['page']):1;//Set the current page number, if not, set it to 1
$num=3;//Display 3 pieces of data per page
/*
First We need to get how much data there is in the database to determine how many pages it needs to be divided into. The specific formula for the total number of pages is
The total number of data divided by the number of items displayed on each page, and the remainder is one.
That is to say, 10/3=3.3333=4 If there is a remainder, we must round it up by one.
*/
$sql="select * from article";
$result=mysqli_query($conn,$sql);
$total=mysqli_num_rows($result);//query data Total number of entries
$pagenum=ceil($total/$num);//Get the total number of pages
//If the page parameter passed in is greater than the total page number pagenum, an error message will be displayed
if($page>$pagenum || $page == 0){
echo "<script>alert('No more content');history.go(-1);</script>";
exit;
}
$offset=($page-1)*$num;
/* Get the value offset of the first parameter of limit, if the first page is (1-1 )*10=0, 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 article limit $offset,$num ";
$info=mysqli_query ($conn,$sql); //Get the data that needs to be displayed for the corresponding page number
//Get the first six newly added data
$sql_new="select id,title from article order by dateline desc limit 0 ,6 ";
$info_title=mysqli_query($conn,$sql_new);
?>

  • reply This is paginated. All I can think of is to put this $page = isset($_GET['page'])?intval($_GET['page']):1;//Set the current page number, if not After setting it to 1, the value of 1 becomes the maximum value, but I don’t know how to set it.
    梁温柔 author 2018-04-11 16:49:06
梁温柔

<?php
//Introducing the paging program
require_once("../paging.php");
//Get 3 pieces of data from the list page and store them in the array $data
if($info&&mysqli_num_rows($info)){
while($row=mysqli_fetch_assoc($info)){
$data[]=$row;
}
}else{
$data=array();
}
//Get the latest 6 added numbers and title information, and store them in the array $data_title
if($info_title&&mysqli_num_rows($info_title)){
while( $row_title=mysqli_fetch_assoc($info_title)){
$data_title[]=$row_title;
}
}else{
$data_title=array();
}
?&gt ;
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no" />
<title> Article list</title>
<meta charset="utf-8" />
<style>
*{
box-sizing:border-box;
}
.box{
font-family: 宋体;
margin:0px auto;
width:400px;
}
.box a:link,.box a:visited,. box a:hover{color:#000000;text-decoration:underline; }
.head{
background-color:#0f8ff2;
height:80px;
}
.tit{
padding: 20px 20px;
font-size:25px;
}
.content{
width:400px;
min-height:100px;
border:1px solid red;
}
.top_con{
width:400px;
padding:10px;
}
.bottom_con{
margin-left:20px;
width: 400px;
}
.con_tit{
font-size:18px;
margin:10px 0px 10px 10px;
font-weight:bold;
}
.con_des{
text-indent:2em;
font-size:18px;
}
.con_det{
padding: 0px 0px 0px 300px;
}
ul{
list-style:none;
margin-left:-40px;

}
li{
margin:15px 0px 0px 0px;
}
.index{
margin:-5px 0px 0px 0px ;
}
.bg{
position:relative;
top: -6px;
background-color:#fff;
margin-left :335px;
}
</style>
</head>
<body>
<div class="box">
<div class ="head"><div class="tit">php information station</div><span class="bg"><a href="../admin/admin_manage.php">Backend entrance</a></span></div>
< div class="content">
<div class="top_con">
<?php
//Loop the data in $data through foreach and display it in the corresponding div
if(!empty($data)){
foreach($data as $value){
?>
<div class="con_tit"><?php echo $value ['title']?></div>
<div class="con_des"><?php echo $value['description']?></div>
&lt ;div class="con_det"><a href="home_show.php?id=<?php echo $value[id];?>">View details</a></div>

<?php
}
}
//Initialize the values ​​​​of the home page, previous page, next page, and last page, and jump to the current page through the <a> tag Page, pass in the value of $page
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pagenum;
?>
<div class="index">
<a href="home_list.php?page=<?php echo $first ?>">Homepage</a>
<a href="home_list.php?page=<?php echo $prev ?>">Previous page</a>
<a href="home_list.php?page =<?php echo $next ?>">Next page</a>
  <a href="home_list.php?page=<?php echo $last ?>"> Last page</a>
 </div>
 </div>
 <div class="bottom_con">
 <div style="margin-left:10px ;margin-top:20px,font-size:20px;">Latest News</div>
  <ul>
    <?php
  //Loop the data in $data_title through foreach and display it in the corresponding div
  if(!empty($data_title)){
foreach($data_title as $value_title){
?>
<li><a href="home_show.php?id=<?php echo $value_title['id']?&gt ;"><?php echo $value_title['title']?></a></li>
                                                                        
</ul>
</div>
</div>
</div>
</body>
</html>


梁温柔

http://www.php.cn/code/4085.html Enter this address to see the code. I need help urgently, now I just need to figure out how to do this in reverse order

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template