kongondo Posted April 28, 2013 Share Posted April 28, 2013 Hi, I have a situation where a sort value is being sent by GET to be processed by another PHP file in PW. The value is being sent via AJAX. The script I am using uses "value ASC" or "value DESC" as sorting parameters. For instance, the sort value could be "name DESC", (sort by name descending). The value is passed to a PW find() to grab some results and sort them according to the sent sort value. Obviously the following will not work with PW selectors: $pages->find("template=basic-page, limit=10, sort=name DESC");// sort will not work How can I convert the sort value coming in via AJAX ("name DESC") (without hacking the core of that script) to achieve "-name" for use in PW selectors as follows? $pages->find("template=basic-page, limit=10, sort=-name"); Thanks. Link to comment Share on other sites More sharing options...
diogo Posted April 28, 2013 Share Posted April 28, 2013 If you have few variations of sort you could do it with a switch statement: switch ($get) { case "name DESC": $sort = -name; break; case "name ASC": $sort = -name; break; // and so on... } If there are more variations you can automate it like this: $sort = explode(" ", $get); $order = $sort[1] == "DESC" ? "-" : "" ; $value = $sort[0]; $pages->find("template=basic-page, limit=10, sort=$order$value"); 3 Link to comment Share on other sites More sharing options...
kongondo Posted April 28, 2013 Author Share Posted April 28, 2013 Diogo, I used the second option. Works a treat! Muito obrigado! Link to comment Share on other sites More sharing options...
diogo Posted April 28, 2013 Share Posted April 28, 2013 De Nada Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now