codehaven - php snippets - coding help
Generic filters
Exact matches only
  • Updating a Mysql column incrementally adding one each time

    12th March 2019

    MySql

    mysql codehaven category

    I had a mysql database that when I add a new value such as 2.5 I wanted to re-order the column with integer numbers (whole). The data column was a decimal(4,1).
    Or in other words – a MySQL auto increment but just resetting values back to an even order using PHP.

    For example
    1.0
    2.5
    3.0
    4.0

    Would be renamed like this
    1.0
    2.0
    3.0
    4.0

    This code will use an sql query to increment a column value by 1.

    Use the code as below (change the column names of course!

    Was this code snippet helpful?