Forum Moderators: coopster
if (!empty($_COOKIE['__utma']))
{
$query = "SELECT views FROM `article` WHERE
`articletag`='{$_GET['show']}'";
$views['art'] = $db->query($query);
$views = $views['art']['0']['views'];
if (empty($views)){$views = '0';}
$views++;
$query = "UPDATE `article` SET `views` = '{$views}' WHERE
`articletag`='{$_GET['show']}'";
$db->query($query);
}
It is supposed to count a view (updated in the number in "views" for that article) every time the entry is called but exclude views by crawlers.
Today Google Analytics shows 235 views for one page but only 18 have been logged into the database by the script. I believe Google Analytics.
Does anyone know what might be wrong with this code? The script has to run for the page to display and the script will run before the Google Analytics code even gets called into the templated page.
Any help would be really appreciated!
Thanks
Mike
INSERT INTO views VALUES ($articleTag, 1) ON DUPLICATE KEY UPDATE views = views +1;
And the usual caveats apply to using $_GET['show']: make sure you escape special chars and its length doesn't exceed the field size.
It's also possible that $_GET['show'] doesn't contain the value you're expecting. Check the table's contents to see if there are any strange rows in there, also check the return value from $db->query() and log an error if it's wrong.
INSERT INTO views VALUES ($articleTag, 1) ON DUPLICATE KEY UPDATE views = views +1;
Thanks, I'll look into that one.
To clarify, the URl is:
www.example.com/folder/file.php?show=1111111
the number corresponds with a unique article in the database.
File.php contains the code I listed above.
Thanks
Mike