open database


  db = new SQLiteDatabase('db/boxes.sql');
  
  

to create


  // uncomment the block below and 
  // call this script if you lost the database file
  // (visit http://locationofthis/update.php)
  
  /*
  	db->query("BEGIN;
          CREATE TABLE boxes (
                          text CHAR(140),
                          x INTEGER(5),
                          y INTEGER(5)
                  );
          COMMIT;");
  */
  
  

addbox


  
  function addBox(string, db) {
          text = strip_tags(htmlspecialchars(string));
          if (strlen(text)>0) {
                  y = rand(20,600);
                  x = rand(100,800);
                  db->query("BEGIN;
                  INSERT INTO boxes (text,x,y)
                  VALUES ('".text."','".x."','".y."');
                  COMMIT;");
          }
  }
  
  

delete box


  function deleteBox(id, db) {
          if (id == "all")
                  db->query("DELETE FROM boxes");
          else
                  db->query("DELETE FROM boxes WHERE rowid = 'id'");
  }
  
  

update


  
  function update(db) {
          query = "SELECT rowid,text,x,y FROM boxes";
          result = db->arrayQuery(query, SQLITE_ASSOC);
          echo json_encode(result);
  }
  
  

move


  function move(x, y, id, db) {
          db->query("UPDATE boxes set x='x',y='y' WHERE rowid='id'");
  }
  
  

select action


  
  switch (_POST["action"]) {
          case "new":
                  addBox(_POST["text"], db);
                  update(db);
                  break;
          case "delete":
                  deleteBox(_POST["boxid"], db);
                  break;
          case "move":
                  move(_POST["x"], _POST["y"], _POST["id"], db);
                  update(db);
                  break;
          case "update":
                  update(db);
                  break;
          default:
                  break;
  }
  ?>