Displaying the total number of times the node has been accessed
Seriously, you do not need to manually query SQL statements just to get how many times the node has been accessed in Drupal. First, make sure that the Statistics module is enabled. Then, all you need to do is write this piece of code:
$node_stats = array();
$node_stats = statistics_get($node->nid);
print $node_stats['totalcount'];
?>
So why do we need to enable the Statistics module? We need to do it to be able to make use of the said function. In addition, this module will record in the database how many times the node has been accessed. Statistics is a core Drupal module.
Tags: Drupal