Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to increment a value by 1?

Status
Not open for further replies.

pushyr

Programmer
Jul 2, 2007
159
GB
I have this weird problem... i'm trying to increment a value by 1 using the following query, but it increments the value by 2??

for example if the value in column open is 5, i want it to increment by 1 so the value becomes 6, then 7, and so on....

but instead it increments by 2 making the value 5 turn to 7, then 9, then 11, and so on

i've googled this and i can't find any faults with the query so now i'm really scratching my head???

UPDATE 04_article_tracker
SET open = open + 1
WHERE unique_id0 = '$article_id'
 
you can't find any faults with your query because there are no faults with your query

i bet if you run the query outside of php you will see that it works correctly

r937.com | rudy.ca
 
i'm pretty much confined to running the query inside of php. have you ever experienced this issue and is there a workaround?
 
i have encountered this issue before, in database discussion forums, and it usually turns out that the application is executing the query twice

but i have never experienced this issue myself personally, because i code in coldfusion, not php, and it's a lot harder to mess up in coldfusion ;-)



r937.com | rudy.ca
 
I just put this together, tested it and it works just fine.

Code:
<?

$sql = 'UPDATE `testcount` SET count = count + 1;';

$dbserver = mysql_connect("localhost","user","password");	// Connect to MySQL Server
mysql_select_db('magno'); 									// Select database

$Results = mysql_query($sql) or die (mysql_error());

?>

<html>
<head>
<title>Hello There!</title>
</head>
<body>
<h1>Count was done!</h1>
</body>
</html>

Is it possible that you are just looping through your routine more than once?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top