A simple mysql database paging program template _ MySQL
Source: Internet
Author: User
The following is a simple page display template for connecting php to the mysql database for data display. you can modify the description according to the annotations. the SQL statements in the description can be modified by yourself. pay attention to the analysis and observation of the code writing and implementation methods for the relevant paging part .? Php $ linkmysql_connect (localhost, root,) ordie (mysqldatabaseconne) is a simple php connection to the mysql database for data display by page. you can modify the description according to the annotations. the SQL statements in the description can be modified by yourself.
Pay attention to the analysis and observation of the code writing and implementation of the relevant paging part.
$ Link = mysql_connect ('localhost', 'root', '') or die ('MySQL database connect error ');
Mysql_select_db ('your database') or die ('The selected database is not exist ');
?>
// Insert your html code here,
$ SQL = 'SELECT count (*) count from your_table ';
$ Result = mysql_query ($ SQL) or die (mysql_errno (). ":". mysql_error (). "\ n ");
$ Rs = mysql_fetch_object ($ result );
$ RecountCount = $ rs-> count;
$ Show = 20;
$ TotalPage = ceil ($ recountCount/$ show );
$ Page = (isset ($ _ GET ['Page']) & $ _ GET ['Page']> = 0 )? $ _ GET ['Page']: 0;
$ IsLast = ($ page = ($ totalPage-1 ))? True: false;
$ HasNoPre = ($ page = 0 )? True: false;
$ HasNoNext = ($ page ==$ totalPage-1 )? True: false;
$ IsFirst = ($ page = 0 )? True: false;
$ Start = $ page * $ show;
Mysql_free_result ($ result );
?>
// Insert your html code here,
$ SQL = "select * from your_table limit $ start, $ show ";
$ Result = mysql_query ($ SQL) or die (mysql_errno (). ":". mysql_error (). "\ n ");
While ($ rs = mysql_fetch_object ($ result )){
// The html code in this loop is modified more practically.
Echo $ rs-> art_id;
Echo"
";
}
Mysql_free_result ($ result );
?>
$ Str = "$ recountCount records in total, current number". ($ page + 1). "/$ totalPage ";
$ Str. = $ isFirst? "Homepage": "homepage ";
$ Str. = $ hasNoPre? "Previous Page": "Previous page ";
$ Str. = $ hasNoNext? "Next page": "next page ";
$ Str. = $ isLast? "Last Page": "Last page ";
Echo $ str;
?>
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.