SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to reorder data without running another query?

    I have a page that looks like an excel spread sheet. I need to be able to sort this page by different columns. I could make the coulmn headers links to different pages where the query is "ordered by" the appropriate column. The problem is the data is quit large and it takes a while to load.

    Code:
    $Cust_Tables = mysql_query("Select table_id, set_no, dist_id, contact_fname, contact_lname, rest_name, rest_city, rest_state_pr FROM abc_tables where status_2<'6' order by rest_name", $db_link);
    		$tables = mysql_num_rows($Cust_Tables);
    Has anyone done this?

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    This can be done with JavaScript. There is publicly available code out there for this. I would link you to it if I had it.

    Or, you can store the results in a temp file or session on the server. Then instead of hitting the database again you just look there.

  3. #3
    SitePoint Guru MikeBigg's Avatar
    Join Date
    Jun 2004
    Location
    Reading, UK
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the javascript solution work on the whole dataset or just what is displayed in the grid?

    If the result set is, say 2000 records and you display only the first 50, possibly using limit in the query, javacsript would be unable to order the result set without running another query as it doesn't have access to all the records.

    As your data currently takes a while to load, is there scope for optimising the query and/or the amount of data that is sent to the browser for display. This may make it possible to run a query each time with no significant delays.

    The other thing that comes to mind ... does the data change often? It maybe that you can cache the pages in their different ordered states with the cache being re-created periodically or when the data changes.

    Mike

  4. #4
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll look up the javascript.

    I am only querying what is absolutely necessary, and the data changes often.

  5. #5
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I ended up using sorttable.js to sort my data. The only issue I had with it was that it wouldn't sort if the data was created in the table. I had to run all my queries and do all my functions and save all the results to variables. Then echo the variables in the table. The sorttable.js is surprisingly fast at sorting data.


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
  •