Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort order by user preference 2

Status
Not open for further replies.

calista

Programmer
Jan 24, 2001
545
US
OK, folks, I've been trying to figure this out, but I'm not getting anywhere. Here's what I'm trying to do. I have a discussion board on my intranet site, and I am working on sorting the threads by thread name, number of messages, and last post. So far, I have it so the user can click on the column heading and the threads will sort on that column. I defined the sort order. By thread name, which is the default, it is in ascending order. Number of messages and last post are in descending order. I accomplished this by making the column heading a link to itself and passing URL variables. What I trying to get to is this, if the user clicks on the same heading again, the sort order will reverse. Any ideas?

Thanks! Calista :-X
Jedi Knight,
Champion of the Force
 
Define sort order by cookie... and then just say...

a href="?origsort=#currentcolumnheadingsort#&newsort=#columnheadingtodefinethesort#"

and then in application.cfm
<CFPARAM name=&quot;cookie.sortway&quot; default=&quot;ASC&quot;>
<cfif currentcolumnheadingsort is columnheadingtodefinethesort>
<CFIF cookie.sortway is &quot;ASC&quot;>
<CFCOOKIE name=&quot;SortWay&quot; value=&quot;DESC&quot; expires=&quot;NEVER&quot;>
<CFELSE>
<CFCOOKIE name=&quot;SortWay&quot; value=&quot;DESC&quot; expires=&quot;NEVER&quot;>
</CFIF>
</CFIF>

and then just utilize cookie.sortway in your sql order by statement.
 
oops.. use this

<cfif currentcolumnheadingsort is columnheadingtodefinethesort>
<CFIF cookie.sortway is &quot;ASC&quot;>
<CFCOOKIE name=&quot;SortWay&quot; value=&quot;DESC&quot; expires=&quot;NEVER&quot;>
<CFELSE>
<CFCOOKIE name=&quot;SortWay&quot; value=&quot;ASC&quot; expires=&quot;NEVER&quot;>
</CFIF>
</CFIF>
 
Been thinking about a simple way of doing this forever; thanks a bunch Webmidget!

One question though: I already have the following code in my application.cfm file for my login checker. Should I place the columnsort code into the file as well? I'm just curious as to if and how much i can stuff into the application.cfm file for future purposes.

<cfapplication name=&quot;loginApp&quot; sessionmanagement=&quot;Yes&quot; clientmanagement=&quot;yes&quot; sessiontimeout=&quot;20&quot;>
<cfparam name=&quot;Session.UserName&quot; default=&quot;&quot;>
<cfparam name=&quot;Session.Password&quot; default=&quot;&quot;>
 
Still trying to implement the cookie sort; any chance you have an example?

 
Nope no examples.. that was my theory on the fly...

Need some help? Let me know..

I'm on AIM as : Webmigit
 
Here's the full code for anyone who wants it...

<CFPARAM name=&quot;cookie.SortWay&quot; default=&quot;ASC&quot;>
<CFPARAM name=&quot;cookie.oSort&quot; default=&quot;DEFAULTCOLUMNHEADINGTOSORTBY&quot;>
<CFPARAM name=&quot;newSort&quot; default=&quot;&quot;>
<CFPARAM name=&quot;origSort&quot; default=&quot;&quot;>

<CFIF len(origsort) gt 0>
<CFIF cookie.oSort is &quot;#newsort#&quot;>
<CFIF cookie.SortWay is &quot;ASC&quot;>
<CFCOOKIE name=&quot;SortWay&quot; value=&quot;DESC&quot; expires=&quot;NEVER&quot;>
<CFELSE>
<CFCOOKIE name=&quot;SortWay&quot; value=&quot;ASC&quot; expires=&quot;NEVER&quot;>
</CFIF>
</CFIF>
<CFCOOKIE name=&quot;oSort&quot; value=&quot;#origsort#&quot; expires=&quot;NEVER&quot;>
</CFIF>
 
Thanks, webmigit! That sounds like it will do the trick! Calista :-X
Jedi Knight,
Champion of the Force
 
Hey, webmigit! I got this working, and it looks great! But, there's just one little thing I haven't been able to figure out. I have three columns I am sorting. For column 1, the default is ASC, which is fine. However, for columns 2 and 3, I want the default to be DESC. So, your first click on column 2 or 3 should be in descending order. How do I do this? Thanks a million for the code! I doubt I would have ever thought of using cookies. Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top