I have a table (Gamepage) with the fields of 'id Description viewcount' The table has 10 records. Each record creates a dynamic php page... template.php?&id=1, template.php?&id=2, template.php?&id=3 etc (Based on the number in 'id' field -in Gamepage) I want a counter on each dynamic php page (so on the template) Which increases the value in the 'viewcount' field by one everytime it is viewed? Can anyone help me achieve this please? Thanks alot, James
ok... here is the update query.. update Gamepage set viewcount = viewcount + 1; for table structure use following query show create table Gamepage;
I knew that top line, but how do i make it increase each record/dynamic page when it is viewed? -How does mysql know which record needs updating?
your url are template.php?id=1, template.php?id=2. id is already there in url... just get it from there and use it in query. $id = $_GET['id']; ....... $update_query = "UPDATE Gamepage SET viewcount = viewcount + 1 where id = '$id'"; PHP:
Are you sure that is right? I enter it into MySQL (to test)... (UPDATE Gamepage SET viewcount = viewcount + 1 WHERE id = '1') (-1 for example) And it returns... Affected rows: 0 (Query took 0.0002 sec) And 'viewcount' has not been affected =/ Any thoughts?
Or if i just try to update it... (As a test)... UPDATE 'Gamepage' SET 'viewcount' = 4 WHERE 'id' = 1 MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Gamepage' SET 'viewcount' = 4 WHERE 'id' = 1' at line 1 Whats up? =/
please share table structure using that query.. let me see the structure then only i can tell you exact query. don't you even try to change the query based on the table?
omg, so sorry. Got it working now, Silly column names, i swapped them around... I should listen to you more and doubt myself... Thanks,
$id = $_GET['id']; $update_query = "UPDATE Gamepage SET viewcount = viewcount + 1 where id = '$id'"; $result=mysql_query($update_query); try that