OO PHP, Dynamic Menu Sortability, & Database Updates

OO PHP, Dynamic Menu Sortability, & Database Updates

I have found jQuery examples of how this can be done using html post data. But when I apply it to my OOP web app I cannot get it to work. There is defiantly something I'm missing. I am very new to jQuery.

Here is what I am trying to accomplish.

I have a CMS app with pages for CRUD. Each page requires header.php, which contains the html header info and html body elements common to every page. My menu navigation div lives in this header.php file. A PHP function, navigation(), is what outputs an unordered list of Categories pulled from a database, ordered by a "position" column. This function is located in a required file called functions.php. I have classes Database, DatabaseObject, and Category (which extends DatabaseObject).

All of the above is working, but I want to have the user be able to reorder the categories by dragging and dropping, and the database update the new positions.

I'd very much appreciate some help.

header.php  code:
----------------

<?php require_once("../../includes/initialize.php"); ?> // loads database, classes and functions

<head>
...
<script type="text/javascript" src="../javascript/jquery-1.10.2.js"></script>
<script type="text/javascript" src="../javascript/jquery-ui-1.10.3.custom.js"></script>
<script type="text/javascript">



   $(document).ready(function() {
        
        $(function() {

          $("#navigation ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {

              var order = $(this).sortable("serialize") + '&action=updateRecordsListings';

              $.post("update_positions.php", order);    
          }         
       });
   });
 
</script>




</head>

<body>
...
   <div id="container">
      <?php Category::find_selected_category(); ?>
     



      <div id="navigation">
   
         <?php echo navigation($current_category); ?>
       
      </div>
      <div id="main_content">





functions.php code:
-------------------

...
<?php
function navigation( $current_category=null ) {
  
   $category_set = Category::find_all_order_by_attribute("position");
 
   $output = "<ul id=\"selectable\">"; 
 
   foreach ($category_set as $category) { 
  
      $output .= "<a";  
      $output .=" href=\"admin.php?category=";
      $output .= urlencode($category->id);
      $output .= "\">";
      $output .= "<li";













      if($current_category) {

  if($category && $category->id == $current_category->id){ 
     $output .= " class=\"selected\"";
  }
      }
      $output .= ">";
      $output .= htmlentities($category->cat_name);
      $output .= "</li> ";
      $output .= "</a>";
   }
   $output .= "</ul>";
     
   return $output;  
}
?>
...














update_positions.php code:
--------------------------

<?php require_once("../../includes/initialize.php"); ?> //db connection, loads classes and functions
<?php  
   $action = mysql_real_escape_string($_POST['action']);
   $updateRecordsArray  = $_POST['recordsArray'];


   if ($action == "updateRecordsListings"){
 
      $listingCounter = 1;
      foreach ($updateRecordsArray as $recordIDValue) {
 
         $query = "UPDATE categories SET position = " . $listingCounter . " WHERE id = " . $recordIDValue;
        
         Category::db_query($query); // calls msqli_query() in DatabaseObjects class using a Database object
         
         $listingCounter++; 
      } 
   }
?>