Study

How to Create go to Next page or previous page in Php

In this article i am gone to share how you can create a  Previous Post and Next Post in php using just simple logic

For go on Previous Post this SQL Query used

$id=5

select * from artical where id < '$id' order by id DESC LIMIT 1

For go on Next Post this SQL Query used

$id=5

select * from artical where id > '$id' order by id ASC LIMIT 1

Implementation in code…

For go on Previous Post

$sql="select * from artical where id < '$id' order by id DESC LIMIT 1";
$result= mysqli_query($link, $sql);
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($resultpr)){
$pr_id = $row['id'];
$pr_title = $row['title'];
echo ' <a href="post.php?artical_id='.$pr_id.'" > $pr_title</a> ';
}
}else{
echo '<span>No More Post</span>';

}

For go on Next Post

$sqln="select * from artical where id >'$id' order by id ASC LIMIT 1";
$resultn= mysqli_query($link, $sqln);
if(mysqli_num_rows($resultn)>0)
{  while($row = mysqli_fetch_assoc($resultn)){ $nx_id = $row['id'];
$nx_title = $row['title']; echo ' <a href="post.php?artical_id='.$nx_id.'" > $nx_title</a> ';
}
}
else{ echo '<span>No More Post</span>'; }