How to Update Database field value +1 in CodeIgniter

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:

12 Responses to “How to Update Database field value +1 in CodeIgniter”

  1. Nezar December 28, 2012 at 5:22 am #

    Niiiiiiiiiiiiiiiiiiiiiiiiice post ^______________^

  2. sothorn July 9, 2013 at 6:46 am #

    Oh. I can do it well thank alot

  3. Tman December 26, 2013 at 6:02 pm #

    Niiiiiiice ^_^

    • Rick December 27, 2013 at 1:07 pm #

      Glad you liked it 😉

  4. bhavik December 16, 2014 at 12:24 pm #

    update query in ci how to create and use uadate qurey

  5. bhavik December 16, 2014 at 12:25 pm #

    give me a full code

    • Rick December 16, 2014 at 10:03 pm #

      Please?

  6. dave December 23, 2014 at 6:48 pm #

    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 December 23, 2014 at 10:31 pm #

      That’s definitely not normal. I wouldn’t know what the problem is from here, without looking at the code.

  7. Deepa September 20, 2017 at 9:27 am #

    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 September 20, 2017 at 9:47 am #

      I would guess you would need to first get the value, and properly do this condition in regular PHP

  8. Visitorpanel February 10, 2018 at 12:59 pm #

    After a great effort on my local server, i have found this and it was helpful.

Leave a Reply

Add <code> Some Code </code> by using this tags.