Paging issues are a very common problem that developers will almost encounter, and they don't discuss how to make specific pages, indicating the principle of the page of the web mode. The first is to obtain a result set (the result of the query database obtained), if the result is more, we generally do not display all the data, then some data (such as 20) is displayed in a paging method (such as 20). Because of the state of HTTP, each submission is handled as a new request, even if it is a change page, the last result is no effect on the next time.
Here, three ways to achieve paging, don't know if there is anything else! 1. Take all the data of the query results each time, then display the specified record according to the page number. 2. Take only one page data according to the page, then display this page, here you want to construct the SQL statement. 3. Take the data of a certain number of pages is the previous compromise.
It is also important to note that these data is placed in Request or session, here discussed
1. Generally not placed in the session, because it takes a lot of memory, so put it in the Request. Advantages: It is relatively simple, and the query speed is faster. Disadvantages: More memory, more network transmission data. This method is relatively appropriate for query queries with a less data. Here people put the data in the session, do not need to re-query when they change the page, but this is extremely bad, it is highly recommended not to use it.
2. It is definitely not placed in the session because it is meaningless in session. Advantages: Take up less memory. Disadvantages: Trouble, you must first get the total number of query results, because you have to know how many records know how many pages. Also construct a page query statement, which is different for different databases.
3. This situation is certainly in the session, otherwise I will take a few pages, this implementation is to reduce the number of database queries, such as the record of the 1st to 10, then if it is changed 1 to 10 can be obtained directly from Session. If you change to 11 pages, I can reset the cache 11 to 20 pages (or 5 to 15 data), such a message is required to need a database query operation. Advantages: There is no much memory, and the average query speed is increased. Disadvantages: It is more complicated, and there may be dirty data, and you need to define a cache collection. If the amount of queries are large, you can consider using this way.