Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,071
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Toggle Sort Order on Hyperlink Click

    Still need some help with sorting!!

    Here is the new functionality that I added...

    1.) The following Inbox Column Headings are hyperlinked: "From", "Subject", and "Date"


    2.) When a User clicks on one of those links, the URL changes like this...
    Code:
    www.Debbie.com/messages/incoming/by-sender
    
    or
    
    www.Debbie.com/messages/incoming/by-subject
    
    or
    
    www.Debbie.com/messages/incoming/by-date

    3.) By clicking on one of the Column Heading links, the page reloads and the Inbox messages are sorted accordingly.


    (I think this all works well, and I used Tango and Fou's advice and incorporated variables into my Prepared Statements.)


    Now, I would like to make it so that clicking on the same link toggles the Sort Order, BUT I don't want to add a "SortOrder" variable in the URL, so this should all be handled "behind-the-scenes" using a Session variable...

    (*NOTE: For the solution... No Cookies. No JavaScript. Just Session variables.)

    I found some hints online, BUT this is the problem that they don't account for...


    The Sort Order should just change when a given link is clicked again and again, HOWEVER, the Sort Order should NOT change if the page is just re-loaded, e.g. hitting F5...


    I've been playing around with some ideas using ternary conditions and the Session, but haven't figured things out yet, and could use some help.

    Sincerely,


    Debbie

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    No cookies = no sessions. Mission failed.

    I can show you a way to do it without sessions / cookies but you won't like it because it does involve using the url.

    Should I continue or will you say no to it?
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,071
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    No cookies = no sessions. Mission failed.
    "No Cookies" *implies* "No (Standard) Cookies, but a Session Cookie is okay..."


    Quote Originally Posted by tangoforce View Post
    I can show you a way to do it without sessions / cookies but you won't like it because it does involve using the url.

    Should I continue or will you say no to it?
    I don't want to add anymore to my "Pretty URL" (i.e. No Sort Order).

    But I live for using $_SESSION, so using that to do what I need behind-the-scenes is just fine.

    Remember, though, the tricky part is...

    When a User clicks on a hyperlinked Column Heading, the Messages should be sorted by that Column and the Sort Order should toggle each time the link is clicked, HOWEVER, just refreshing the page should not change the Sort Order!!

    Why?

    Because when people refresh the page to check for new Messages, they will not want the Sort Order changing!!

    Hope that makes sense?!

    Sincerely,


    Debbie

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by doubledee View Post
    Remember, though, the tricky part is...
    I know what the tricky part is.. I also know you probably won't find what you're looking for

    Quote Originally Posted by doubledee View Post
    When a User clicks on a hyperlinked Column Heading, the Messages should be sorted by that Column and the Sort Order should toggle each time the link is clicked, HOWEVER, just refreshing the page should not change the Sort Order!!

    Why?

    Because when people refresh the page to check for new Messages, they will not want the Sort Order changing!!
    You're going to have a headache here because unless you submit some sort of random token in the url (which you're saying no to), the server won't know the difference between a refresh and a normal request - they're the same thing anyway. You have to give the server / script *some* way of knowing what the request is in order for it to know if it should change direction or not.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,071
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    I know what the tricky part is.. I also know you probably won't find what you're looking for

    You're going to have a headache here because unless you submit some sort of random token in the url (which you're saying no to), the server won't know the difference between a refresh and a normal request - they're the same thing anyway. You have to give the server / script *some* way of knowing what the request is in order for it to know if it should change direction or not.
    But even if I had "SortOrder" in the URL, how would my PHP know whether the URL came from a request where one of the Column Headings was clicked - and thus a re-sort is needed - versus a simple Page Refresh??

    (Page refreshes would submit the same URL as when you click on a Column Heading, right?!)

    Sincerely,


    Debbie

  • #6
    New Coder
    Join Date
    Nov 2011
    Location
    Ratio, Logic
    Posts
    60
    Thanks
    3
    Thanked 6 Times in 6 Posts
    You are making to complications for something noone would use (except if you are making bank account for kidnappers), but ok.
    I can't see anyting bad in link like:
    PHP Code:
    www.Debbie.com/messages/incoming/by-sender/asc 
    or
    PHP Code:
    www.Debbie.com/messages/incoming/by-sender/desc 
    And problem solved IMHO.

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by doubledee View Post
    But even if I had "SortOrder" in the URL, how would my PHP know whether the URL came from a request where one of the Column Headings was clicked - and thus a re-sort is needed - versus a simple Page Refresh??
    Because you switch the direction in the url like this:

    http://www.debbies-spandex.com/messa.../by-sender/asc

    or

    http://www.debbies-spandex.com/messa...by-sender/desc

    When your user clicks one of those, you check in your script which one it is and then output the OPPOSITE one in the url for that column. Refreshes will produce the same order with the same opposite links.

    I will PM you something that will demonstrate this in action - something I've been working on recently.
    Last edited by tangoforce; 11-11-2013 at 01:45 AM.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #8
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,071
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    Because you switch the direction in the url like this:

    http://www.debbies-spandex.com/messa.../by-sender/asc

    or

    http://www.debbies-spandex.com/messa...by-sender/desc

    When your user clicks one of those, you check in your script which one it is and then output the OPPOSITE one in the url for that column. Refreshes will produce the same order with the same opposite links.

    I will PM you something that will demonstrate this in action - something I've been working on recently.
    Tango, I'm willing to add /asc|desc to my URL, but I think I need an expert on Mod_Rewrites, because adding that last parameter BROKE my Mod_Rewrite...

    (And I *HATE* screwing with Mod_Rewrites, because I don't consider myself an expert on them, and so creating a new URL for which I don't have a known-tested-and-certified Mod_Rewrite is a scary proposition for me!!)

    Sincerely,


    Debbie
    Last edited by doubledee; 11-11-2013 at 02:02 AM.

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    I wouldn't use asc/desc per se, I'd use a or d which naturally relate to their directions. You can then hard code the direction according to what letter you find.

    As for the .htaccess, post it and I'm sure someone will advise. I'm off to bed now (2am) so it probably won't be me BUT what I will say is that you'll probably need an almost identical line to the one you have but with an extra /(.*) after it. Also remember to use the [L] flag at the end of the line to tell apache to stop processing the file when it finds a matching rule.

    Here is a sample of mine that I used:

    Code:
    RewriteRule sort/(.*)/(.*)/(.*).html/(.*)/$ /structure/database/index.php?al=$1&direction=$2&column=$3&page=$4 [L]
    RewriteRule sort/(.*)/(.*)/(.*).html$ /structure/database/index.php?al=$1&direction=$2&column=$3 [L]
    RewriteRule sort/(.*)/(.*).html$ /structure/database/index.php?al=$1&column=$2 [L]
    RewriteRule ^map-(.*)/(.*).html$ /structure/database/map.php?tunnel=$2&direction=$1 [L]
    RewriteRule (.*).html/(.*)/$ /structure/database/index.php?al=$1&page=$2 [L]
    RewriteRule (.*).html$ /structure/database/index.php?al=$1
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •