PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 25th, 2008, 06:30 PM
wilorichie wilorichie is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Brisbane
Posts: 324 wilorichie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 15 h 29 m 24 sec
Reputation Power: 3
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

Reply With Quote
  #2  
Old November 29th, 2008, 02:25 AM
amber.long83 amber.long83 is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 32 amber.long83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 6 m 47 sec
Reputation Power: 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

Reply With Quote
  #3  
Old December 1st, 2008, 09:55 AM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
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:
<a href="page.php?
<?php
if(isset($_GET['order'])) {
if($_GET['order']=='ASC') {
echo "
&order=DESC";
} elseif($_GET['order']=='DESC') {
echo "
&order=ASC";
}
} else {
//Echo opposite of default here
echo "
&order=DESC";
}
?>"
>
<?
php
if(isset($_GET['order'])) {
if(
$_GET['order']=='ASC') {
echo 
"Sort in Descending Order";
} elseif(
$_GET['order']=='DESC') {
echo 
"Sort in Ascending Order";
}
} else {
//Echo opposite of default here
echo "Sort in Descending Order";
}
?>
</a> 

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:
<?php
$link 
"page.php?";
if(isset(
$_GET['order'])) {
if(
$_GET['order']=='ASC') {
$link .= "&order=DESC";
} elseif(
$_GET['order']=='DESC') {
$link .= "&order=ASC";
}
} else {
//Echo opposite of default here
$link .= "&order=DESC";
}
?>

<?php
$innerhtml 
"Sort";
if(isset(
$_GET['order'])) {
if(
$_GET['order']=='ASC') {
$innerhtml .= " in Descending Order";
} elseif(
$_GET['order']=='DESC') {
$innerhtml .= " in Ascending Order";
}
} else {
//Echo opposite of default here
$innerhtml .= " in Descending Order";
}
?>
</a>
<a href="<?php echo $link?>"><?php echo $innerHTML?></a>


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:
<a href="page.php?order=ASC&page=2">Page 2ASC order</a>
<
a href="page.php?order=DESC&page=2">Page 2DESC order</a>
<
a href="page.php?order=ASC&page=3">Page 3ASC order</a>
<
a href="page.php?order=DESC&page=3">Page 3DESC order</a
__________________
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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > logic - Order by asc/desc filter


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek