The PHP paging query assumes that the table name is A and the record data is unknown. & nbsp; it is best to use a SELECT implementation for each problem & nbsp; 1. retrieve the first 10 records in the table. (It should be written in reverse physical order) & nbsp; 2. retrieve the last 10 records in the table. (It should be written in reverse physical order) & nbsp; 3. retrieve 10th entries from the table to the PHP paging query
Assume that the table name is A and the record data is unknown.
It is best to use a SELECT statement for each problem.
1. retrieve the first 10 records in the table. (this should be written in reverse physical order)
2. retrieve the last 10 records in the table. (this should be written in reverse physical order)
3. fetch 10th to 20th records from the table (which should be written in reverse physical order)
4. retrieve the records used in the table, and add the two columns as the row number and the physical row number.
---------------------------
1. select * from a limit 0, 9
2. select top (10) from a order by id desc
3. select * from a limit 9, 19
---------------------------
Create table sort ('col1' INT (3) unsigned not null, 'col2' CHAR (1) not null, primary key (Col1), INDEX Col2 (Col2 ));
Insert into sort (Col1, Col2) VALUES (1, 'A ');
Insert into sort (Col1, Col2) VALUES (2, 'C ');
Insert into sort (Col1, Col2) VALUES (3, 'B ');
Insert into sort (Col1, Col2) VALUES (4, 'd ');
Insert into sort (Col1, Col2) VALUES (5, 'F ');
Insert into sort (Col1, Col2) VALUES (6, 'E ');
Insert into sort (Col1, Col2) VALUES (7, 'H ');
Insert into sort (Col1, Col2) VALUES (8, 'g ');
Insert into sort (Col1, Col2) VALUES (9, 'k ');
Insert into sort (Col1, Col2) VALUES (10, 'J ');
Insert into sort (Col1, Col2) VALUES (11, 'L ')
Insert into sort (Col1, Col2) VALUES (12, 'I ');
Insert into sort (Col1, Col2) VALUES (13, 'n ');
Insert into sort (Col1, Col2) VALUES (14, 'M ');
SELECT * FROM Table1 Limit 0, 10;
# Obtain the first 10 in physical order
SELECT * FROM Table1 Limit 10, 10;
# Obtain 10 from 10th in physical order
Query the total number of records first.
SELECT Count (*) As Count FROM Table1;
Then, process the SQL statement as shown above in your own program.
As for the reverse query by physical order,
Haha,
:《
---------------------------
$ SQL = "select cardid, company, name from namecard where ";
......
$ SQL. = "limit $ offset, 10 ";
$ Result2 = mysql_query ($ SQL );
While ($ row = mysql_fetch_array ($ result2 ))
{
Show_card ($ row );
}
$ Pages = ceil ($ num/10 );
Echo "";
Echo "({$ pages} pages in total) \ n ";
If ($ offset> = 10) // $ offset is greater than 9, the previous page is displayed above the second page.
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