2

Ok, here is the code i have for my pagination:

    $SQL = "SELECT
            cpc.product_id,
            cp.product_internal_ref,
            cp.product_name,
            cpa.product_sale_price,
            cpa.is_product_service,
            cpa.product_service_price,
            cpi.image_name,
            cpi.image_ext
            FROM catalog_products_categories cpc 
            JOIN catalog_products cp ON cp.product_id = cpc.product_id
            JOIN catalog_products_attributes cpa ON cpa.product_id = cpc.product_id
            LEFT JOIN catalog_products_images cpi ON cpi.product_id = cpc.product_id
            WHERE cpc.category_id = ".$catID;

    // PAGINATOR SECTION
    if($paginatorVARS['paginatorACTION'] == "next") {
      $SQL .= " AND cpc.product_id > ".$paginatorVARS['paginatorGOID']." ";
      $SQL .= "GROUP BY cpc.product_id ORDER BY cpc.product_id ASC LIMIT ".$paginatorVARS['catalogPaginatorPAGEROWS'];
    }
    elseif($paginatorVARS['paginatorACTION'] == "prev") {
      $SQL .= " AND cpc.product_id < ".$paginatorVARS['paginatorGOID']." ";
      $SQL .= "GROUP BY cpc.product_id ORDER BY cpc.product_id DESC LIMIT ".$paginatorVARS['catalogPaginatorPAGEROWS'];
    }
       // END PAGINATOR SECTION

I used the method described here: http://www.slideshare.net/Eweaver/efficient-pagination-using-mysql but i can't seam to find a way to also sort by other columns like for example by cpa.product_sale_price. If i do : ORDER BY cpc.product_id ASC, cpa.product_sale_price DESC/ASC it will break the paginator next results i dont know what happens... Please help!!

1 Answer 1

1

not saying their stuff is perfect, but it is often a place to start, to consider if you really want to reinvent the wheel, or take their concepts and incorporate it into your new rounder wheel. take a look at

http://dev.sencha.com/deploy/ext-4.0.0/examples/grid/paging.html

and use fiddler to examine the http gets that are occuring during pagination, as well as changes in the sort context. when it starts out it brings back the http response header, json data with jsonp callback, and top node value at the end of the json data specifying record count=6679 / 50 per page meaning 134 pages total as calculated by the front-end. the record count can vary from call to call (from page to page) as rows are inserted and deleted.

the sort column gets passed in the query string just like the pages impact the limit start,total that goes into sql. this can be seen in fiddler output showing changes in pages or sort column requests (column name, and asc or desc):

GET /forum/topics-browse-remote.php?_dc=1369401925806&page=1&start=0&limit=50&sort=lastpost&dir=DESC&callback=Ext.data.JsonP.callback1 HTTP/1.1

GET /forum/topics-browse-remote.php?_dc=1369401977137&page=1&start=0&limit=50&sort=replycount&dir=ASC&callback=Ext.data.JsonP.callback2 HTTP/1.1

GET /forum/topics-browse-remote.php?_dc=1369401978355&page=1&start=0&limit=50&sort=replycount&dir=DESC&callback=Ext.data.JsonP.callback3 HTTP/1.1
Sign up to request clarification or add additional context in comments.

5 Comments

I'm not trying to invent anything .. but to implement a better paginator into my catalog which i saw clearly it's faster then using LIMIT OFFSET. My problem is that i cannot make it order results by something else but the id that is needed for the actual steps of the paginator.
well then consider sencha paginating grids. you can slice and dice the sort order and go directly against mysql. here is another example: docs.sencha.com/extjs/4.2.0/extjs-build/examples/grid/… you can drag the columns up to the sort area, and drag the sort order to the left and right of each other. dozens of ways to configure theirs sorts and paging
Sorry but i cannot approve your message. You did not provided a solution to my problem.. although you tried :). I still want to handle the 'sorting' from the backend in mysql.
it is handled by the mysql svr as php gets query posts and constructs the sql query string with order by clause and limit start,total. extjs is just a gui wrapper for issuing the calls to the php post query strings and for consuming returned json data. extjs does not sort, mysql does. extjs communicates back to the middleware things like, hey, i am on page 7, give me page 8, or, i have a completely different sort order now, so my pages are messed up, refeed me data based on my new sort column(s) ... good luck !
I don't think it's possible to order by non unique values in my example.. that is the real problem...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.