topical media & game development

talk show tell print

basic-ajax-12-tasks.php / php



  <?php
      function getTasks()
      {
          query = 'SELECT task_id, task FROM tasks ORDER BY rank';
          result = mysql_query(query);
   
          tasks = array();
          while (row = mysql_fetch_object(result)) {
              tasks[row->task_id] = row->task;
          }
   
          return tasks;
      }
  
      function taskOrder(key)
      {
          if (!isset(_POST[key]))
              return;
   
          tasks = getTasks();
          queries = array();
          rank = 1;
   
          foreach (_POST[key] as task_id) {
              if (!array_key_exists(task_id, tasks))
                  continue;
   
              query = sprintf('UPDATE tasks SET rank = \%d WHERE task_id = \%d',
                               rank,
                               task_id);
   
              mysql_query(query);
              rank++;
          }
      }
  ?>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.