Use direct database Update instead of Model to increment a field +1
I always use the CodeIgniter models to do all the MySQL querys (insert, select, updates...) but this won't work if you want to update a count field +1.
Use this direct code in your Controller Function:
$this->db->set('my_field', 'my_field+1', FALSE);
$this->db->where('my_other_field', 'test');
$this->db->update('my_table');
Code language: PHP (php)
Nezar
Niiiiiiiiiiiiiiiiiiiiiiiiice post ^______________^
sothorn
Oh. I can do it well thank alot
Tman
Niiiiiiice ^_^
Rick
Glad you liked it π
bhavik
update query in ci how to create and use uadate qurey
bhavik
give me a full code
Rick
Please?
dave
ive applied the above function to add +1 but is adding by 5….is that a common thing or how can I fix it
Rick
That’s definitely not normal. I wouldn’t know what the problem is from here, without looking at the code.
Deepa
how to increment the value by check the previous value in db if db_field = 5 increase +1 if db_field =10 increase +3 lyk that is this possible
Rick
I would guess you would need to first get the value, and properly do this condition in regular PHP
Visitorpanel
After a great effort on my local server, i have found this and it was helpful.
Philip
Hi! I have this kind of case in CI: In column A I have values e.g. 1, 5, 20 linked to unique id. In column B I would like to add values from column A like: row 1: 1, row 2: 6, row 3: 26. These values are linked as well to unique id – the same by the row.
Values from table A I'm entering row by row in modal window and saving into database. So, when I enter value e.g. 5, 1 in already recorded in database.
Is it possible to make it in CI?
Regards, Philip
marry
my fieild is database name