saynotojava Posted August 1, 2018 Share Posted August 1, 2018 (edited) I am using following pagination class: https://github.com/BenGriffiths/pdo-mysqli-pagination and i have specific situation where i cant use ordering inside mysql query. How do i change sorting in this pagination class, where loading first page wont load first page but last page instead ? (that way i'l get proper sorting) Edited August 1, 2018 by saynotojava Quote Link to comment Share on other sites More sharing options...
requinix Posted August 2, 2018 Share Posted August 2, 2018 If you can't sort in the query then you have to retrieve all the data and do all the work yourself. And that is a terrible thing to be forced into. Why do you say you can't do it in a query? Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted August 2, 2018 Share Posted August 2, 2018 If you look at their example it's got an "order by id" in the query passed to the pagination object. Put either ASC or DESC after that depending on whether you want ascending or descending. In your case DESC. Quote Link to comment Share on other sites More sharing options...
saynotojava Posted August 2, 2018 Author Share Posted August 2, 2018 16 hours ago, requinix said: If you can't sort in the query then you have to retrieve all the data and do all the work yourself. And that is a terrible thing to be forced into. Why do you say you can't do it in a query? It's a specific query in specific situation which require order by NULL to make it work properly. It does sounds like a terrible thing, but since i have this class already, it should be possible to reverse page output, so page 1 become page 10,page 2 become 9 and so on. Quote Link to comment Share on other sites More sharing options...
requinix Posted August 2, 2018 Share Posted August 2, 2018 But... if it's already sorting by the correct criteria just in the wrong order, then all you have to do is reverse the order. What's your code? Maybe it will be easier to understand your problem if we can see that. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 2, 2018 Share Posted August 2, 2018 "order by NULL" What is that? Is "NULL" a table column name or what? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 2, 2018 Share Posted August 2, 2018 Apparently SQLServer queries involving ROW_NUMBER column in the output requires an ORDER BY to be specified, even if it is a dummy one like "ORDER BY NULL". This could be one of those situations, but at the moment it's just speculation. Quote Link to comment Share on other sites More sharing options...
saynotojava Posted August 2, 2018 Author Share Posted August 2, 2018 27 minutes ago, requinix said: But... if it's already sorting by the correct criteria just in the wrong order, then all you have to do is reverse the order. What's your code? Maybe it will be easier to understand your problem if we can see that. There is not much difference between example code and my code, only difference is sql query and obviously HTML layout. Everything else is same as in example code. Quote Link to comment Share on other sites More sharing options...
saynotojava Posted August 2, 2018 Author Share Posted August 2, 2018 7 minutes ago, Barand said: Apparently SQLServer queries involving ROW_NUMBER column in the output requires an ORDER BY to be specified, even if it is a dummy one like "ORDER BY NULL". This could be one of those situations, but at the moment it's just speculation. Actually, when i tested different queries, when you dont specify ORDER in query, by default it order by ID(alias first column). So if you dont want ORDER to run , then you need to specify NULL. Quote Link to comment Share on other sites More sharing options...
requinix Posted August 2, 2018 Share Posted August 2, 2018 4 minutes ago, saynotojava said: only difference is sql query That's an important difference. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 2, 2018 Share Posted August 2, 2018 Decide what order you want it in then specify the ORDER BY clause to put it in that sequence. Without any more info from you that's the best we can give you. Good luck. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.