-1

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

database.png

5
  • which row you wanna update? Commented Oct 19, 2016 at 11:34
  • You want a query to increment or you are looking for a PHP Script for incrementing the values? Commented Oct 19, 2016 at 11:34
  • why you just turn auto increment in the structure settings on? Commented Oct 19, 2016 at 11:35
  • Do you want to increase the id column? OR any other column? Commented Oct 19, 2016 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 Commented Oct 19, 2016 at 11:48

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

Comments

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)

2 Comments

Welcome to Stack Overflow, here we do not like W3schools links but otherwise, great answer. :)
@4796321 oh ok. Here is the SQL update reference then: mariadb.com/kb/en/mariadb/update/#syntax (I have edited the answer in consequence).
1
"UPDATE table_name
 SET column_name = column_name+ 1
 WHERE condition";

Hope this help

1 Comment

Please stop using mysql_ functions, as they have been removed from PHP

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.