# how do i add 1 to the amount of mysql BIGINT Field?



## emopoops (Jan 27, 2009)

what is the atribute of BIGINT in mysql that starts with just a 0 not 000000000000 or blank? i figured out my code was wrong but that question still remains


----------



## Big-K (Nov 22, 2003)

Give it a 'default' attribute of '0'. To increment it, use something like "UPDATE table SET field1 = (field1 + 1)".


----------



## ClayC (Jul 25, 2008)

mysql_query("UPDATE `table` SET `field`=`field`+1");

that is a quick way to do it or you can do it the long way which I don't suggest

Considering you only have 1 field

$data = mysql_fetch_array(mysql_query("SELECT * FROM `table`"));
$data[field] .= 1;
mysql_query("UPDATE `table` SET `field`='$data[field]");
$data = "";

the last line is to make sure no data is saved to variable so no user will or can get other fields etc... or you can replace the * in the SELECT function and make it (`field`)

of course you must replace table with the table name and field with the field name 

Hope this helped


----------



## Big-K (Nov 22, 2003)

For the record, the second way mentioned in the previous post won't work. The '.=' operator will concatenate the 1 to whatever field already is, ending up with something like 51 or 5561 instead of 6 or 557. The correct operator would be '+='. Either way, its a terrible way to do it, as it requires two queries and multiple function calls for php.


----------

