"Php+mysql" blog page production ideas, phpmysql ideas _php Tutorial

Source: Internet
Author: User

"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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.