SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    caught in a cache?

    Hello!

    I'm not quite sure where to put this post as the problem may be php, mysql, jquery, or ajax related. So, here goes:

    I'm developing a web page which allows users to reorder a list. The list itself appears twice on the page, once as a table of contents off to the side (which can't be manually resorted) and a second list that can be resorted. I'm then using jquery's sortable to resort the second list, and then using ajax to call a php script which 1) updates my database 2) removes a cache with has the old list. When I refresh the page the cached list changes (the one that wasn't manually resorted), while the dynamically generated list using php/database doesn't change. Further, when I look at my database, the order field has been in fact updated.

    What's even more confusing is that the script works fine locally. Is it possible that since I'm using ajax my server somehow doesn't know that I've updated the database and uses some sort of server-side cached result?

    Thank you for any thoughts.

    -Eric

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,282
    Mentioned
    180 Post(s)
    Tagged
    4 Thread(s)
    it sounds, by your description, like BOTH lists are reading from the same set of data.
    Your apparent intention is - with AJAX - to repopulate only the second list but I would guess your AJAX response is also affecting the first list.
    If you can provide a snippet of [PHP] code here, there are many who can help guide you.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the quick response! After the ajax call, if I refresh the page, both lists should actually show the new order. The ajax call is:

    Code:
     $.ajax({
                        url: "/main_scripts/sort_chapters_and_sections.php",
                        type: "POST",
                        data: newOrder,
                        success: function(thing_reordered){
    										//here I'll print something
                        
    										}
    The php script which gets called is:
    PHP Code:
        if (isset($_POST['section'])) {
                
    $new_order "";
                foreach (
    $_POST['section'] as $order =>$book_section_id) {
                    
    $data['book_order'] = $order+1;
                    
    $where['book_section_id = ?'] = $book_section_id;
                    
    $updated $dbWrite->update('book_topics',$data,$where);
                }
                require_once(
    '../main_scripts/cache_setup_for_headers.php');
    $nav_left_cache->remove('nav_left_cache');
            } 
    After I refresh the page, the 'nav_left_cache' gets successfully repopulated with the new order (there's a separate script which populates that area if there's nothing in the cache. However, another list doesn't get refreshed even though it's dynamically generated from my database.

  4. #4
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry! It was a sql issue on my part. I had:

    PHP Code:
     AND topic=".$dbRead->quote($current_section_name)." 
                     
    AND section_name <>".$dbRead->quote($current_section_name)." AND book_id " . $dbRead->quote($book_id).
                     " 
    ORDER by book_order"; 
    when it should have been:

    PHP Code:
     AND topic=".$dbRead->quote($current_section_name)."  AND section_name <>".$dbRead->quote($current_section_name)." ORDER by book_order AND book_id " . $dbRead->quote($book_id); 
    Strange that the location of the ORDER statement had no effect locally...


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
  •