Okay I have seen a post around here about this before but I had no luck finding it. I have a more complexed way of doing this but I saw there was a really simple way where you just have a little script in the mysql query. Okay here is what I was looking for:
I need a script that would +1 to a number in the database.
Thanks.
dEcade
+ 1 to database
Started by dEcade, Jan 21 2006 10:00 AM
3 replies to this topic
#1
Posted 21 January 2006 - 10:00 AM
#2
Posted 21 January 2006 - 02:56 PM
$query = mysql_query("UPDATE table SET row = $variable + 1 WHERE id = 4)";
Something like that, just change to work for you.
Something like that, just change to work for you.
#3
Posted 21 January 2006 - 03:26 PM
After connecting to the database run the following query...
Leave out the WHERE clause to update every record in the table.
If you want a whole script you'll have to tell us what language (PHP?) and what database (MySQL?).
UPDATE your_table SET value = value + 1 WHERE id = 1
Leave out the WHERE clause to update every record in the table.
If you want a whole script you'll have to tell us what language (PHP?) and what database (MySQL?).
Edited by veridicus, 21 January 2006 - 07:34 PM.
#4
Posted 21 January 2006 - 06:29 PM
Just here to point a couple of things out about the previous comments (under the assumtion we're working with php/mysql).
1.
), i believe that query would give a mysql error. When it parses $variable to what ever value it is, it will look for a column by the same name, and find out it's most likely not there.
2. UPDATE doesn't accept the FROM clause since you already define your_table in the beginning.
Other then that, if you mix the 2, you should have a working query.
http://dev.mysql.com.../en/update.html <-- More info
1.
$query = mysql_query("UPDATE table SET row = $variable + 1 WHERE id = 4)";
Other then having the end quote in the wrong place (which i'm not going to hold against you, simple key stroke error 2. UPDATE doesn't accept the FROM clause since you already define your_table in the beginning.
Other then that, if you mix the 2, you should have a working query.
http://dev.mysql.com.../en/update.html <-- More info
Edited by rc69, 21 January 2006 - 06:30 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
