someone can tell me how to update the value from 0 to 1, 52 to 53 (value++) using php script? i want to search it on go*gle but i dunno the keyword to find it
Asked
Active
Viewed 2,601 times
-1
-
which row you wanna update? – Masivuye Cokile Oct 19 '16 at 11:34
-
You want a query to increment or you are looking for a PHP Script for incrementing the values? – VishalParkash Oct 19 '16 at 11:34
-
why you just turn auto increment in the structure settings on? – Luca Jung Oct 19 '16 at 11:35
-
Do you want to increase the `id` column? OR any other column? – masterFly Oct 19 '16 at 11:36
-
i want to update 5_sangat_baik, 4_baik, 3_cukup, 4_buruk, 5_sangat_buruk, but depending on the user which script he/she want to access – Flix Oct 19 '16 at 11:48
3 Answers
2
If you want to update one column, for example 5_sagnat_baik
- just run the query:
UPDATE `question` SET `5_sagnat_baik` = `5_sagnat_baik` + 1

Battle Mage
- 369
- 2
- 5
1
"UPDATE table_name
SET column_name = column_name+ 1
WHERE condition";
Hope this help

VishalParkash
- 490
- 3
- 15
-
1[Please stop using mysql_ functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), as they have been removed from PHP – Machavity Oct 19 '16 at 12:40
1
You may update your auto-increment column (known as 'id') using a "update" sql in your php script using something like:
'UPDATE table_name SET id=(id + 1), [column2]=[value2], ...'
OR with PHP computed values (here $current_value):
'UPDATE table_name SET id=' . $current_value + 1 ', [column2]=[value2], ...'
The SQL update request is explained here: http://www.w3schools.com/SQl/sql_update.asp (or here: https://mariadb.com/kb/en/mariadb/update/#syntax)

user6815451
- 31
- 1
- 5
-
1Welcome to Stack Overflow, here [we do not like W3schools links](http://meta.stackoverflow.com/questions/280478/why-not-w3schools-com) but otherwise, great answer. :) – Sainan Oct 19 '16 at 11:48
-
@4796321 oh ok. Here is the SQL update reference then: https://mariadb.com/kb/en/mariadb/update/#syntax (I have edited the answer in consequence). – user6815451 Oct 19 '16 at 11:55