Hi,
Whats the best way to add 1 to an entry? do I have to read it into a variable add one to that variable and then write it back to the database? or is there a way to just automatically increase an entry?
thanks for any help boombanguk
UPDATE table SET field = feild + 1
of course use a WHERE clause to specifiy certain row(s)
i tried this and it didn't work
$query = mysql_query("UPDATE ".$table." SET viewed = 'viewed+1' WHERE index = '".$id."' LIMIT 1");
".$table."
viewed
index
More likely:
$query = mysql_query("UPDATE `".$table."` SET `viewed` = `viewed`+1 WHERE `index` = '".$id."' LIMIT 1");
tried that, but the entry just stays at 1....
Are you sure that the query is correct, with the correct $id?
yes because the entry was zero before, i ran the code, and then it made it 1, and then it stays at 1, it doesn't increase
ok i think i figured it out, it needed to be
$query = mysql_query("UPDATE `".$table."` SET viewed = viewed+1 WHERE `index` = '".$id."' LIMIT 1");
That is unusual. With what you have given, all I can say is that it must be something else.