Pagination-limit & Offset (python)

Source: Internet
Author: User

(based in PostgreSQL)

Limit:if a limit count is given, no more than taht many rows being returned (but possibly less, if query itself yields less Rows

Offset: offset says to skip this many rows before beginning to return rows to the client. Offset 0 is the same as omitting the offsetclause. If both offset and LIMIT appear, then OFFSET rows is skipped before starting to count the limit rows that is returned.

SELECT select_list    From Table_expression    | All}] [OFFSET number]

Fetch:retrieve rows from a query using a cursor

FETCH [Direction {from | in}]CursornamewhereDirection can be emptyorOne of:    NEXTPRIOR First Last ABSOLUTECountRELATIVECount    Count     AllFORWARD FORWARDCountFORWARD AllBackward BackwardCountBackward All

About Direction Parameters Information in:http://www.postgresql.org/docs/8.1/static/sql-fetch.html

Pagination:

Pagination_limit = 20
offset = get_http_argument ('Offset', optional=true)or1Offset=int (offset) offset= OffsetifOffset > 0Else1Limit=pagination_limit Offset= (offset-1) *Limit Result= db (). List (" "SELECT *, COUNT (*) over () as Total_rows
From TestOFFSET%(offset) s FETCH first% (limit) ROWS only" ", Offset=offset, Limit=limit)

  

Total_pages = Total_rows/limit

You can get different results by request a different page:

{% if total_pages > 1}<Divclass= "pagination pagination-centered mt-10">                <ulclass= "Clearfix inline-block">{% if offset > 6}<Li><ahref= "javascript:void (0)">1</a></Li>                        <Li><aclass= "Disabled"href= "javascript:void (0);">...</a></Li>{% endif%} {% for I in range (offset-5, offset)%} {% If i > 0}<Liclass= "Inline-block"><ahref= "javascript:void (0);">{{i}}</a></Li>{% endif%} {% endfor%}<Liclass= "Current Inline-block"><aclass= "Current"href= "javascript:void (0);">{{offset}}</a></Li>{% for I in range (5)%} {% if offset + loop.index<= Total_pages%} <li class= "Inline-block"><ahref= "javascript:void (0);">{{offset + loop.index}}</a></Li>{% endif%} {% endfor%} {% if total_pages > offset + 5} <Li><aclass= "Disabled"href= "javascript:void (0)">...</a></Li>                        <Li>                            <ahref= "javascript:void (0)">{{Total_pages |int}}</a>                        </Li>{% endif%}</ul>            </Div>{% endif%}

Pagination-limit & Offset (python)

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.