December 2013
Intermediate to advanced
306 pages
6h 26m
English
Finding the number of affected rows can be useful in several ways—perhaps you want to update some records and only proceed if a certain number of records are updated, or perhaps you simply want to display the number of rows that have been deleted or updated by a query.
function update($id, $data) {
$this->db->where('id', $id);
if ($data->db->update($data, 'table_name')) {
return $this->db->affected_rows();
} else {
return false;
}
} The model function update() accepts two parameters: a $data array and the $id array of the database row we wish to update.
Next, we test for the returned value of $this->db->update($data);, which will return ...
Read now
Unlock full access