1. First, you need to initialize and set the number of articles displayed on each page $page_size, the total number of articles in the mysql database $arc_size, and the number of pages $page
2. Use the paging formula
(current page number - 1) X Number of items per page, Number of items per page
Select * from table limit ($Page- 1) * $PageSize, $PageSize This is the query sql statement in mysql. Here we assume n=($Page- 1) * $ PageSize, m=$PageSize means to query the content from the table data table, starting from n and ending with n+m. The code is as follows:
$conn = @mysql_connect("localhost","root","liujiang") or die("Failed to connect to database server!"); //Connect ly_php_base Database $ok = @mysql_select_db("myblog_base",$conn) or die("Failed to connect to the database!");mysql_query("set names 'utf8'"); //Solved the failure to insert Chinese characters into the mysql database question, please note that utf8 must be consistent with
if($ok){echo "mysql is ok!";}else {echo "mysql is failed!"; }$page=$_GET['page'];//Get the current page valueif (!isset($page)){$page=1;} //If there is no value, assign 1$page_size= 2;//Display 2 items per page$arcs_result=mysql_query("select count(*) as total from myblog_article");//The output result is Resource id #4$arc_size=mysql_result($arcs_result,0,"total ");//Total number of articles
$pagenum=ceil($arc_size/$page_size); $offset=($page-1)*$page_size; $sql=mysql_query("SELECT * FROM myblog_article WHERE 1 order by id asc limit $offset,$page_size"); //desc means descending order, which means starting from $offset, ranking $page_size times Article title: Article type: Article introduction: Upload time: Article author:[]page
if($sql){echo "query yes";}else {echo "query no" ;}
$rs=mysql_fetch_array($sql); //Extract data
while($rs) {
?>
?"$i":"$i";
Echo $show." ";
}
?>
The above introduces the ideas for creating blog pagination, including some aspects. I hope it will be helpful to friends who are interested in PHP tutorials.