"Php+mysql" blog page production ideas, phpmysql idea of pagination
1, first need to initialize set the number of articles displayed per page $page_size,mysql total number of articles in database $arc_size, number of pages $page
2, the use of the page formula
(Current page-1) X number of pages per page, number of articles per page
($Page-1) * $PageSize, m=$PageSize meaning from the table data table, starting from N, until n+m out the end of the content query out 3, display the contents of the database The code is as follows: $conn = @mysql_connect ("localhost", "root", "Liujiang") or Die ("the connection to the database server failed!") ");
Connecting the Ly_php_base Database
$ok = @mysql_select_db ("Myblog_base", $conn) or Die ("failed to connect to the database! ");
mysql_query ("Set names ' UTF8 '"); To solve the problem of failing to insert Chinese characters into MySQL database, note here that UTF8 must be This is consistent in the
if ($ok) {echo "MySQL is ok!";} else {echo "MySQL is failed!";}
$page =$_get[' page '];//to get the current value
if (!isset ($page)) {$page = 1;}//If there is no value, then assign a value of 1
$page _size=2;//2 records per page
$arcs _result=mysql_query ("SELECT count (*) as Total from myblog_article");//The output is resource ID #4
$arc _size=mysql_result ($arcs _result,0, "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 sort, meaning starting from $offset, $page_size times
if ($sql) {echo "Query yes";} else {echo "Query No";}
$rs =mysql_fetch_array ($sql); Extracting 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 ":"
$i";
Echo $show. " ";
}
?>
http://www.bkjia.com/PHPjc/1096604.html www.bkjia.com true http://www.bkjia.com/PHPjc/1096604.html techarticle "php+mysql" blog page production ideas, phpmysql ideas 1, the first need to initialize the number of articles displayed per page $page_size,mysql total number of articles in the database $arc_size, number of pages ...