Home | Products | Consulting | Hosting | Forums | Support | Order | 1-800-752-0455
  Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Hit Counter

 

 


vinco
User

Jun 20, 2008, 7:48 AM

Post #1 of 2 (544 views)
Shortcut
Hit Counter Can't Post

Is there any way to add a hit counter (number of time viewed) to news articles?

Thank you for your help


Dave
Staff / Moderator


Jun 20, 2008, 11:10 AM

Post #2 of 2 (524 views)
Shortcut
Re: [vinco] Hit Counter [In reply to] Can't Post

No, we don't have a feature for that. But if you're comfortable editing code you can try the following:

- Open /lib/viewer_functions.php
- Make a backup copy of that file
- Add this to this to bottom just above ?>


Code
// Note: This function is EXPERIMENTAL and may change in future 
function incrementCounterField($tablename, $fieldname, $recordNumber) {
global $VIEWER_NAME;

// error checking
if (!$tablename) { die(__FUNCTION__ . ": No 'tablename' value specified!"); }
if (!$fieldname) { die(__FUNCTION__ . ": No 'fieldname' value specified!"); }
if (!$recordNumber) { die(__FUNCTION__ . ": No 'recordNumber' value specified!"); }

// update counter
$escapedTableName = mysql_real_escape_string(getTableNameWithPrefix($tablename));
$query = "UPDATE `$escapedTableName` SET `$fieldname` = `$fieldname` + 1";
$query .= " WHERE `num` = " .mysql_real_escape_string($recordNumber);
$result = @mysql_query($query);
if (!$result) { die(__FUNCTION__ . " MySQL Error: ". htmlspecialchars(mysql_error()) . "\n"); }
if (!mysql_affected_rows()) {
die(__FUNCTION__ . ": Couldn't find record '" .htmlspecialchars($recordNumber). "'!");
}

}


Then create a field called 'hits' (or whatever you want to call it) add this in your page. This first field is the tablename, the second field is the fieldname, and the third field is the record number


Code
<?php incrementCounterField('news', 'hits', $newsRecord['num']); ?>


Hope that helps.

Dave Edis - Senior Developer
interactivetools.com

 
 
 


Search for (options)
Products
CMS Builder
Article Manager
Realty Manager
Listings Manager
Order Now
Services
Priority Consulting
Hosting
Support
Online Documentation
Support Forums
Support Homepage
Company Info
12 reasons to choose us!
Meet the team
Monthly newsletter
Contact Us
Toll Free: 1-800-752-0455
Phone: (604) 689-3347
Sales | Support
Conditions of Use | Privacy Policy | Copyright © interactivetools.com 2008
#201 - 2730 Commercial Drive, Vancouver BC Canada V5N 5P4