[php]
this php counter script adds 1 everytime the page is refreshed.
problem is that the page its on uses id’s to render, so the content is never the same depending on what id was loaded. how can I make it work based on the page’s url if that makes sense?
this is the code:
<?php include_once "../login/includes/dbconnect.php"; $sql = "SELECT counter FROM counter"; $result = mysql_query($sql) or die (mysql_error()); $rows = mysql_fetch_array($result); $page_views = $rows['counter']; if (empty($page_views)) { $page_views = "1"; mysql_query("INSERT INTO counter (counter)VALUES('1')"); } echo "Video has " .$page_views. " views."; $page_views++; $sql = "UPDATE counter SET counter = $page_views"; $result = mysql_query($sql) or die (mysql_error()); ?>this is the table
CREATE TABLE counter
(
counter
int(11) NOT NULL default ‘0’
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
[/php]