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
Like Tree1Likes
  • 1 Post By Arcticwarrio

Thread: Sorting Data on Page without using URL

  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Sorting Data on Page without using URL

    Here is a trickier question that is somewhat related to this thread Submitting Form changes Query String in URL...


    Is there a practical way to Sort Data on a page WITHOUT putting Sort Parameters in the URL?

    (Like the last thread, I do not want to use JavaScript this time around...)


    Here is what I am trying to accomplish...

    For Articles on my website, the URL currently looks like this...
    Code:
    www.debbie.com/finance/markets/yellen-will-keep-rates-low

    By itself, this looks a.) Simple, b.) Sleek, and c.) Easy to read, but here is the kicker...

    Beneath each Article is an Article-Comments section similar to most online newspapers. And as more and more Comments get posted, the scroll and load times might increase to where they are not manageable, so I want to add Sorting and Pagination to my Article-Comments section similar to how I did in the thread above.

    The problem is that I do NOT want an ugly Query String mucking up my pretty Article URL!!!

    (I don't mind the Query String on my Subsection page, but for Articles, I want to keep things as simple as possible in the URL.)


    So, if a user chooses to sort Article-Comments by "Rating" - or wants to navigate to Page 3 - then is there some way that when they submit the Form, that I can avoid having the Sort and Pagination parameters in the URL??


    The only way I can think to handle things is by using $_SESSION, but I'm not sure if that would work?!

    Sincerely,


    Debbie

  • #2
    Regular Coder
    Join Date
    Jun 2009
    Posts
    145
    Thanks
    3
    Thanked 21 Times in 21 Posts
    I dont know what you are searching for as I am sure you are well aware of the ways PHP can transmit data from page to page

    GET
    POST
    COOKIE
    SESSION
    HEADER

    The best way to deal with pagenation/order sorting is using a mixture of javascript (ajax) with post. Not sure why you dont want to do this, you have just ruled out the most viable option with no explanation. If you dont want the URL affected dont use GET, but Ajax would be best as it wont affect your URL but can dynamically load more articles...

  • #3
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by itxtme View Post
    I dont know what you are searching for as I am sure you are well aware of the ways PHP can transmit data from page to page

    GET
    POST
    COOKIE
    SESSION
    HEADER

    The best way to deal with pagenation/order sorting is using a mixture of javascript (ajax) with post. Not sure why you dont want to do this, you have just ruled out the most viable option with no explanation. If you dont want the URL affected dont use GET, but Ajax would be best as it wont affect your URL but can dynamically load more articles...
    I don't know JavaScript.
    I don't like JavaScript.
    I don't have time to learn it this go-round.
    And my website is JavaScript free and will remain so for v2.0

    Sincerely,


    Debbie

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Posts
    462
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Since it's only for article comments and not actual article pages use sessions, it will still have to reload the page either way unless you use an iframe to manage the comments.
    Then you can design the frame and manipulate the paging etc without reloading the main page.
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    For projects using MediaTypes (MIMETypes) visit E-BAM.net -(updated weekly)

    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    723
    Thanks
    20
    Thanked 84 Times in 84 Posts
    yes deb session is fine,

    $_SESSION['sort'] = 'ratings';
    $_SESSION['direction'] = 'desc';
    $_SESSION['page'] = '3';
    if isset($_SESSION['sort']){

    //etc

    }
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #6
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arcticwarrio View Post
    yes deb session is fine,

    $_SESSION['sort'] = 'ratings';
    $_SESSION['direction'] = 'desc';
    $_SESSION['page'] = '3';
    if isset($_SESSION['sort']){

    //etc

    }
    I think I follow what you and c1lonewolf are recommending, so that would solve one problem.

    But my other related issue is that I also want to have Pagination for the User Comments, and currently my PHP is generating links like this...
    PHP Code:
        // Other Page.
        
    $commentsNavigation .= "<li><a href='/$section/$subsection/$article?sortname=$sortName&sortdir=$sortDir&page=$page'>$page</a></li>\r\n"

    Because those are hyperlinks that creates two issues...

    1.) Google can crawl then - which I am trying to avoid

    2.) I don't see how I could use a $_GET or $_POST like I can with the Command Button associated with my Sort Drop-down Field and Form.


    Any ideas how to tackle that issue?

    Sincerely,


    Debbie

  • #7
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    723
    Thanks
    20
    Thanked 84 Times in 84 Posts
    change the link to a form
    PHP Code:
    $commentsNavigation .= "<li>
    <form id='nav_form' method='post'>
    <input type='hidden' name='sortname' value='$sortName'>
    <input type='hidden' name='sortdir' value='$sortDir'>
    <input type='hidden' name='page' value='$page'>
    <a href='javascript:{}' onclick=document.getElementById('nav_form').submit(); return false;'>$page</a>
    </form></li>\r\n"

    i know you dont like javascript, you can use a button instead and format it using css to look like text
    <input class='linkButton' type='submit' value='$page'>

    css:
    .linkButton {
    background: none;
    border: none;
    color: #0066ff;
    text-decoration: underline;
    cursor: pointer;
    }
    Last edited by Arcticwarrio; 05-07-2014 at 10:28 PM.
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #8
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arcticwarrio View Post
    change the link to a form
    PHP Code:
    $commentsNavigation .= "<li>
    <form id='nav_form' method='post'>
    <input type='hidden' name='sortname' value='$sortName'>
    <input type='hidden' name='sortdir' value='$sortDir'>
    <input type='hidden' name='page' value='$page'>
    <a href='javascript:{}' onclick=document.getElementById('nav_form').submit(); return false;'>$page</a>
    </form></li>\r\n"

    i know you dont like javascript, you can use a button instead and format it using css to look like text
    <input class='linkButton' type='submit' value='$page'>

    css:
    .linkButton {
    background: none;
    border: none;
    color: #0066ff;
    text-decoration: underline;
    cursor: pointer;
    }

    Thanks for the alternative, but it's still "cheating" (i.e. using JavaScript).

    As far as I can see, I will have to live with "?page=1" in my URL if I use a Navigation Bar which relies on hyperlinks.

    Of course if anyone has another idea that helps me accomplish what I want and not use JavaScript, then I'm all ears!

    Sincerely,


    Debbie

  • #9
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    723
    Thanks
    20
    Thanked 84 Times in 84 Posts
    PHP Code:
    $commentsNavigation .= "<li>
    <form id='nav_form' method='post'>
    <input type='hidden' name='sortname' value='$sortName'>
    <input type='hidden' name='sortdir' value='$sortDir'>
    <input type='hidden' name='page' value='$page'>
    <input class='linkButton' type='submit' value='$page'>
    </form></li>\r\n"

    css:
    .linkButton {
    background: none;
    border: none;
    color: #0066ff;
    text-decoration: underline;
    cursor: pointer;
    }
    moinul likes this.
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

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