stuieb Posted March 31, 2008 Share Posted March 31, 2008 Hi, I'm new here but really do need some help. I have a site that is PHP and MySQL and it has detail pages that are served via a url string like view_page.php?recordID=xxx. I want to insert an update comand on the page to count hits. I know the difference between hits and page views etc, but just need to count the number of times the page is loaded (by whatever means). I have the code as follows which can be used in a static page: mysql_query("UPDATE tabel set hits = hits+'1'"); but I can't figure out how to do a WHERE id=(url variable recordID) so that just that record in the database gets updated. Please help. Many thanks in advance, Stu. Link to comment https://forums.phpfreaks.com/topic/98813-dynamic-hit-counter/ Share on other sites More sharing options...
Goose87 Posted March 31, 2008 Share Posted March 31, 2008 I'm not sure if this is the best method to use, but you could use something like: if(isset($_GET['recordID'])){ $id=@mysql_real_escape_string($_GET['recordID']); if((mysql_num_rows(mysql_query("SELECT id FROM table WHERE id='$id'")))==0){ echo 'Error Message'; } else { @mysql_query("UPDATE table set hits=hits+1 WHERE id='$id'"); } } I haven't tested the code, but give it a go Link to comment https://forums.phpfreaks.com/topic/98813-dynamic-hit-counter/#findComment-505635 Share on other sites More sharing options...
stuieb Posted March 31, 2008 Author Share Posted March 31, 2008 Fantastic, Just the ticket. Many thanks. Stu. Link to comment https://forums.phpfreaks.com/topic/98813-dynamic-hit-counter/#findComment-505683 Share on other sites More sharing options...
Goose87 Posted March 31, 2008 Share Posted March 31, 2008 I'm glad I could assist you Link to comment https://forums.phpfreaks.com/topic/98813-dynamic-hit-counter/#findComment-505686 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.