Home  >  Article  >  Backend Development  >  [php mysql] Blog paging production ideas, phpmysql paging ideas_PHP tutorial

[php mysql] Blog paging production ideas, phpmysql paging ideas_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:59:511014browse

[php mysql] Blog paging production ideas, phpmysql paging ideas

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, number of pages $page

2. Use paging formula

(current page number - 1) In the data table, query the content starting from n out to n m out.
3. Display the contents of the database 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'"); //Solve the mysql database The problem of failure to insert Chinese characters into . 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 value
if (!isset($page)){$page=1;} //If 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, sorting $page_size times
if($sql){echo "query yes";}else {echo "query no";}
$rs=mysql_fetch_array($sql); //Extract data
while($ rs) {
?>


Article title:


Article type:


Article introduction:


Upload time:

Article author:[]page



$rs = mysql_fetch_array($sql);
}
For($i=1;$i<=$pagenum; $i ){


$show=($i!=$page)?"$i< /a>":"$i";
Echo $show." ";


}?>


http://www.bkjia.com/PHPjc/1096604.html

truehttp: //www.bkjia.com/PHPjc/1096604.htmlTechArticle[php mysql] Blog paging production ideas, phpmysql paging ideas 1. First, you need to initialize the number of articles displayed on each page. $page_size, the total number of articles in the mysql database $arc_size, the number of pages...