Here's my query, in CodeIgniter's Active Record:
function calculate_invites($userid)
{
$this->db->where('id', $userid)
->update('users', array('invites' => 'invites-1', 'sentinvites' => 'sentinvites+1'), FALSE);
}
The fields invites
and sentinvites
are both integers but are set to 0 after the function is run. This makes me presume that CodeIgniter is passing invites-1
and sentinvites+1
as strings, but I thought appending FALSE
to the end stopped it doing that?
Thanks!
Jack
Active Record Class CodeIgniter uses a modified version of the Active Record Database Pattern. This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. In some cases only one or two lines of code are necessary to perform a database action.
Apparently, if $key is an array, codeigniter will simply ignore the second parameter $value, but the third parameter $escape will still work throughout the iteration of $key, so in this situation, the following codes work (using the chain method): However, this will unescape all the data, so you can break your data into two parts:
This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. In some cases only one or two lines of code are necessary to perform a database action. CodeIgniter does not require that each database table be its own class file. It instead provides a more simplified interface.
you can load the date helper and use the codeigniter interal now () if you want to reference the users GMT time offset If you don't use the GTM master settings and let your users set their own offsets there is no advantage over using php's time () function.
This doesn't work with update
, only with set
.
This should work:
$this->db->where('id', $userid);
$this->db->set('invites', 'invites-1', FALSE);
$this->db->set('sentinvites', 'sentinvites+1', FALSE);
$this->db->update('users');
This may work too (the user guide is a bit unclear):
$this->db->where('id', $userid);
$this->db->set(array('invites' => 'invites-1', 'sentinvites' => 'sentinvites+1'), FALSE);
$this->db->update('users');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With