$views++; echo $views; //2 mysql_query("update vehicles set hits = '$views' where id = '$id' limit 1"); echo $views; //2 Code (markup): This is the problem, lets say my previous views are 1. after $view++ it should be 2 but after the update query tables is updated with 3 I cannot really find why this happening, why mysql add extra 1
It doesn't look like there are any problems with what you have right there. I would suggest going through your code with a fine-tooth comb. A possibility might be that auto-increment is on for the "hits" column, or something weird like that.
Thank you for the replies problem was that, this page was requested 2 times before actually loading the page I don't know why but after I removed a table from my page it worked find. page was only requested one time.
An easier way to increase the counter field in the database would be: mysql_query("update vehicles set hits = hits+1 where id = '$id' limit 1"); Code (markup): Then you wouldn't need to involve the $views variable from php. Although if you're fetching it from the database anyway to display it on the page then you might as well keep the code as it is.