Trongate Docs
switch to dark modeswitch to dark mode
»
»
The 'Update' Method

The 'Update' Method

The 'Update' method updates rows on a table table. It accepts the following parameters:

  • $update_id (required) - the 'id' value for the record that is to be updated.
  • $data (required) - an array of key, value pairs that represents that new data to be used in the table update.
  • $target_table (optional) - the name of the database table to be updated. By default, the Model will assume the target table to be equal to the value on the first URL segment.

What Gets Returned?

The 'Update' method does not return anything.

Example 1

The syntax below shows the simplest Update example possible.  Here we are changing the 'last_name' value from a table row and we are doing so for a record with an 'id' of 6.

$data['last_name'] = 'Claptout';
$this->model->update(6, $data);

The code above will produce the following SQL query:

UPDATE `tablename` SET `last_name` = 'Claptout' WHERE `members`.`id` = 6

Just To Let You Know
In a working example, 'tablename' would be replaced with the first segment from the URL.

Below is an example of a Members.php controller file that contains a test() method.  Here we're invoking a basic 'Update' command and then immediately displaying the results using Trongate's json() method:

<?php
class Members extends Trongate {

function test() {
    $data['last_name'] = 'Claptout';
    $this->model->update(6, $data);
}

Below shows an example of the kind of output that we can expect to see from the above method, when Debug Mode is switched on:

screenshot

Example 2

Below is a more advanced example:

<?php 
class Members extends Trongate {
    function test() {
        $data['first_name'] = 'Jimmy';
        $data['last_name'] = 'Page';
        $this->model->update(6, $data, 'members');
    }

The code above would produce the following SQL query:

UPDATE `members` SET `first_name` = 'Jimmy', `last_name` = 'Page' WHERE `members`.`id` = 6


HELP & SUPPORT

If you have a question or a comment relating to anything you've see here, please goto the Help Bar.

 
×