search

Home  >  Q&A  >  body text

php - How to use limit and offset to handle pagination in database multi-condition search?

Part of the table structure is as follows:

 total numeric(20,2), -- statistical amount
  date character varying(50), -- date
  site character varying(50), -- address

Now I want to use a table on the page to output: statistical data corresponding to dates and addresses. One date can correspond to multiple addresses. An address can also correspond to multiple dates, but a date and an address can uniquely determine a record.
I now make statistics based on the date group by, and then search for the corresponding address for each date. In this way, some dates contain multiple addresses, and some dates only contain case of an address. At this time, I cannot use limit and offset to display data in pages. Now I have collected all the data, but this paging cannot be implemented.
How can this problem be solved? Thanks.

phpcn_u1582phpcn_u15822828 days ago391

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-16 13:11:44

    No matter how complex your query is, you can use limit and offset to paginate.

    select * from (
      select a, b, c
      from ...
      where ...
      ...
    ) 
    order by a, b, c
    limit xx
    offset xx;
     

    reply
    0
  • Cancelreply