HEllo guys,
I am having an issue that is anoing me. I have a very simple table (MyISAM) where i have a field "count(INT)(11)"
It's just a counter that's increment every time one product/item is viewed. The problem is that query is incrementing 2 and not 1.
Ie. Actualfield value = 10
than i run: mysql_query("update table_test set count = count+1 where id = 1");
the field count value goes to 12 and not to 11.
I thought maybe my script is runnig 2x the query, then i've done a clean file with this lines:
$con = mysql_connect("localhot","user","pass");
mysql_select_db("database");
mysql_query("update table_test set count = count+1 where id = 1");
and nothing more in the file .. it still add 2 insted 1. but if i copy this query and run using Phpmyadmin it work.
Any have idea of what happening?
Thanx very much Kid regards Tarsis Florencio
This is the full code i am using:
include 'includes/constants.php'; //just db_user, db_pass and connection
include 'includes/connect.php';
//here i select the actual count value
$result = mysql_query("select count from pictures where id = 6909") or die (mysql_error()." - [select count from pictures where id = 6909]");
$row = mysql_fetch_array($result);
$aux = (int)$row['viewed'] + 1; // increment
mysql_query("UPDATE pictures SET viewed = {$aux} WHERE id = 6909");
Also i've try:
mysql_query("UPDATE pictures SET viewed = viewed+1 WHERE id = 6909");
If i run the file using the query like this: UPDATE pictures SET viewed = 15 WHERE id = 6909
where i specify the value to be updated, works.