SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Carrying Sort To Next Page Via Pagination.

    Hello,

    How can I pass SORT variable to next page via pagination.

    SORT CODE:
    PHP Code:
    <?php

    $sort 
    = [$_GET['tableorder'];

    echo
        
    '<table border=0 width=100%>
        <tr>
        <td align=center width=5% align=center>
          <a href="'  
    $_SERVER['PHP_SELF'] . '?tableorder=userid">ID</a>
        </td>
        
    <td align=center width=15%>
        <a href="' 
    $_SERVER['PHP_SELF'] . '?tableorder=Last_Name">&nbsp;LAST NAME</a>
        </td>
        
    <td align=center width=15%>
        <a href="' 
    $_SERVER['PHP_SELF'] . '?tableorder=First_Name">&nbsp;FIRST NAME</a>
        </td>
        
    <td align=center width=10%>
        <a href="' 
    $_SERVER['PHP_SELF'] . '?tableorder=status">&nbsp;STATUS</a>
        </td>

        <td align=center width=15%>
        <a href="' 
    $_SERVER['PHP_SELF'] . '?tableorder=date_created">&nbsp;DATE CREATED</a>
        </td>
        </tr>
        </table>'
    ;

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You can accomplish that by appending &tableorder=$_GET['tableorder'] to the url to every page.
    Saul

  3. #3
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot php_Daemon. I have plugged in the code and it partially work. When I load the page and if I don't SORT the records, this error message pops in:
    PHP Code:
    <?php
    Could not query
    :Unknown column '' in 'order clause'
    ?>
    And If i SORT right after loading the page, I am able to pass the SORT onto the next page. Any ideas?

    Thanks.

    This is how I have the inserted the sort into the code:

    PHP Code:
    <?php

    echo "
    <a href='
    {$_SERVER['PHP_SELF']}?page="$i "&tableorder=$_GET[tableorder]'\> ["$i "]&nbsp;</a>&nbsp;";    

    ?>
    Last edited by ultrajeeps; Apr 4, 2007 at 20:17.

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You have to options:
    1. Check if it's sorted and only then add the tableorder param to the query
    2. Only add ORDER BY clause to the query if there's a table order param set


    Option b makes more sense in terms of that the validity of sql query must not depend on the url query.
    Saul


Bookmarks

Posting Permissions

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