|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
logic - Order by asc/desc filter
Hey guys
I have a page that has pagination. This page also has column titles you can click on to order by that filter. Titles include: Name, ID, Age, Joined I have it at the moment so if you click on the title, it orders it by ASC. It is easy to make it order by DESC but it then troubles me becuase of the pagination as well... Here is the code ordering by just ASC: Code:
if($_GET['sort']){
$sortby = "ORDER BY " .$_GET['sort'] ." ASC";
$sort = "sort=" .$_GET['sort'] ."&";
}
This is the pagination link: Code:
$plink = "qstats.php?$sort"."page="; That pagination link will be used like this: Code:
if($prev_page >= 1){
$prev_link = "$plink$prev_page";
} else {
$prev_link = "$plink$min_page";
}
So, you can see that we know which page the user is on from the $_GET['page'] variable. I need help with making it so if you click on the filter a second time, it then ORDER BY DESC and works with the pagination.. Cheers guys
__________________
- Richie |
|
#2
|
|||
|
|||
|
here you need to manage 2 variable for sorting. one for sort column and another sort order. so your url should be like
for ASC order = abc.php?sort=name&order=asc for DESC order = abc.php?sort=name&order=desc you can change your code to manage this two variable and you will get it done |
|
#3
|
|||
|
|||
|
Richie-
I think what you were trying to figure out is how to click once to display the order of a column one way, then click it again to display it the other way. On the link you should use something like: PHP Code:
After reading the original post again: In order for it to work correctly with pagination, just add some more if/elseif/else statements in there...or instead of echoing &order=DESC , for instance, you could append to a variable: PHP Code:
If this helps, but doesn't completely answer your question, give me an example link of what you are looking to produce...maybe: PHP Code:
__________________
Sir, a desire of knowledge is the natural feeling of mankind; and every human being, whose mind is not debauched, will be willing to give all that he has to get knowledge. Last edited by jamestrowbridge : December 1st, 2008 at 10:07 AM. |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > logic - Order by asc/desc filter |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|