Provides an instance classification function. If you need it, you can refer to it.
<? Php tutorial
// Page Function
$ Page = $ _ get ["page"];
Function page ($ rows, $ page_size ){
Global $ page, $ select_from, $ select_limit, $ pagenav;
$ Page_count = ceil ($ rows/$ page_size );
If ($ page <= 1 | $ page = '') $ page = 1;
If ($ page >=$ page_count) $ page = $ page_count;
$ Select_limit = $ page_size;
$ Select_from = ($ page-1) * $ page_size .',';
$ Pre_page = ($ page = 1 )? 1: $ page-1;
$ Next_page = ($ page = $ page_count )? $ Page_count: $ page + 1;
$ Pagenav. = "$ page/$ page_count page $ rows records ";
$ Pagenav. = "<a href = '? Page = 1'> homepage </a> ";
$ Pagenav. = "<a href = '? Page = $ pre_page '> previous page </a> ";
$ Pagenav. = "<a href = '? Page = $ next_page '> next page </a> ";
$ Pagenav. = "<a href = '? Page = $ page_count '> last page </a> ";
$ Pagenav. = "Jump to <select name = 'topage' size = '1' onchange = 'window. location = "? Page = "+ this. value'> n ";
For ($ I = 1; $ I <= $ page_count; $ I ++ ){
If ($ I = $ page) $ pagenav. = "<option value = '$ I' selected> $ I </option> n ";
Else $ pagenav. = "<option value = '$ I'> $ I </option> n ";
}
} // Page Function
// Example
If (! $ Conn = mysql tutorial _ connect ("localhost", "root", "root") die ('database tutorial selection failed! ');
If (! Mysql_select_db ("test", $ conn) die ('database selection failed! ');
Mysql_query ('set names gbk ');
// Use the page function to calculate the records from which $ select_from is retrieved and the pagenav output paging navigation.
$ Rows = mysql_num_rows (mysql_query ("select * from test "));
Page ($ rows, 2 );
$ SQL = "select * from test limit $ select_from $ select_limit ";
$ Rst = mysql_query ($ SQL );
While ($ row = mysql_fetch_array ($ rst )){
Echo "$ row [id]-$ row [sex]-$ row [name] }
Echo $ pagenav;
?>
The following figure shows the database structure.
Create a database named test
Execute the following statement (create a table named test: id, sex, and name)
Create table 'test '(
'Id' int (4) not null auto_increment primary key,
'Sex 'int (1) not null,
'Name' varchar (20) not null) engine = myisam character set utf8 collate utf8_bin;
Add data to the test table, for example:
1 Xiaoqiang
2 0 red
3 0 Xiaoli
4 1 soldier
5, 1, 3
6 0 Li Si
7 0 Wu Xin