/** * This is the magic set function that really does the work of slaptight. * This allows values that are being set on our slapRow objects to modify * the table that they come from in real time. * * @param string $name * @param string $value */ public function __set($name, $value) { if (!isset($this->parentQuery)) { $this->parentQuery = slapTight::getInstance($parentQueryName); } $table = $this->fieldTable[$name]; $pkey = $this->table[$table]['pkeyName']; if ($pkey == $name) { die("Cannot set the primary key to a different value"); } $sql = "UPDATE `".$table."` SET `".$name."`='".$value."' WHERE `".$this->table[$table]['pkeyName']."`='".$this->table[$table]['pkeyValue']."';"; $this->rowData[$name] = $value; foreach ($this->fields as $key=>$field) { if ($field['name'] == $name) { $this->fields[$key]['value'] = $value; } } $this->db->update($sql); }
1. make a new database. 2. load the database with the included .sql file. (mysql -u root -p -D database name < slapTightTest.sql) 3. update slapTight's config.ini with your database settings. 4. view this file in your browser, as well as with a text editor, so you can follow along. */ include 'slapTight.class.php'; //lets set the selected variable to the code value from get, if it is there. $selected = $_GET['code']; //This is the sql query, and the only sql query that will be used manually by the programmer. $peopleSQL = "SELECT * FROM people"; $stateSQL = "SELECT * FROM states order by name ASC"; //execute the sql query and make an array of slapTight row objects as the result $people = slapTight::select("people", $peopleSQL); $states = slapTight::select("states", $stateSQL); if (($selected == "new") && ($_POST['submitted'] == 1)) { $selected = $people->insert($_POST); } //lets cycle through them all to build the list and some other operations. foreach ($people as $key=>$data) { //if there is no record selecrted, set the default to the first in the list if (!isset($selected)) { $selected = $data->id; } //if we have recieved a submission of data from the form, go ahead and make the changes. //note that there is no sql necessary to update the database with this information. //also note that we are setting the data AFTER the initial query, and still the data // that is presented will be the new data from the post.