PHP programming problems a table in the database has 10 messages. if you want to display them by page, it is such a program: & lt ;? Phpinclude (& quot; conn. php & quot;); connect to the database $ pagesize5; set the number of messages displayed per page $ url $ _ SERVER [& quot; REQUEST_URI & quot;]; to get the current address. And use REQUEST_URL to make it $ u PHP programming problem
There are 10 messages in a table in the database. to display the messages by page, it is such a program:
Include ("conn. php"); // connect to the database
$ Pagesize = 5; // you can specify the number of messages displayed on each page.
$ Url = $ _ SERVER ["REQUEST_URI"]; // Obtain the current address. And use REQUEST_URL
$ Url = parse_url ($ url); // use the parse_url function: parses the url to convert the url into an array.
$ Url = $ url [path]; // Obtain the parsed path. Because there will be many keywords after parsing, such as scheme, host, user, pass, etc .. Call the key method in the array: $ url [key];
$ Numq = mysql_query ("SELECT * FROM 'test" '); // query the database information
$ Num = mysql_num_rows ($ numq); // display the total number of rows using the mysql_num_rows (function name) function ";
If ($ _ GET [page]) {
$ Pageval = $ _ GET [page];
$ Page = ($ pageval-1) * $ pagesize;
$ Page. = ',';
}
If ($ num> $ pagesize ){
If ($ pageval <= 1) $ pageval = 1;
Echo "$ num total ".
"Next page of the previous page ";
}
Echo $ SQL = "SELECT * FROM 'test' limit $ page $ pagesize ";
$ Query = mysql_query ($ SQL );
While ($ row = mysql_fetch_array ($ query )){
Echo"
". $ Row [name]." | ". $ row [sex];
}
?>
Why does $ _ GET [page] appear? Do you need to define this ??? For guidance, the mysteries of this sentence ..
------ Solution --------------------
No variable $ _ page is displayed.
If you are talking about $ page, $ page = ($ pageval-1) * $ pagesize; is the initialization of $ page.