Simple phpwcms counter script here

Discuss phpwcms here, please do not post support requests, bug reports, or feature requests! Non-phpwcms questions, discussion goes in General Chat!
Post Reply
iascoot
Posts: 4
Joined: Sat 28. Feb 2004, 06:16
Location: Dunedin, New Zealand

Simple phpwcms counter script here

Post by iascoot »

Hello

I created a simple phpwcms counter script, it retrieves the vars from phpwcms directly
It just increases each page view, doesnt check to see if user just refreshed the page
Feel free to use the code on your website


To Install you have to use PhpMyAdmin and run this query:

Code: Select all

ALTER TABLE `phpwcms_article` ADD `article_count` INT NOT NULL ;
(if u prepended something onto the table names in setup, change phpwcms_article to that)

Then paste this into a file called count.php (doesnt matter really)

Code: Select all

<?php
/*			This PHP Source was created by Scott Mcleod - 2004©
			Email: iascoot@hotmail.com
			
			Usage: A Simple Counter Script for PHPWCMS (www.phpwcms.de)
			Created:  Saturday, 28 February 2004
			Last Modified:  Saturday, 28 February 2004

*/

// Retrieve The Articles ID
global $content, $sql, $db;
$id = $content["article_id"];
// Retrieve the current count number for the article
	$sql = "SELECT article_count FROM ".DB_PREPEND."phpwcms_article WHERE article_id=$id";
	$result = mysql_query($sql, $db);
	$int = mysql_result($result, 0);
// Update the count number
	$int = $int + 1;
	$sql = "UPDATE ".DB_PREPEND."phpwcms_article SET article_count='$int' WHERE article_id=$id";
	$result = mysql_query($sql, $db);
// Output the result
print $int;
?>

Example Usage:
Page has been Viewed {PHP:count.php} times.
(Page has been Viewed 123 times.)
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

this is why we need a mod forum :lol:
http://www.studmed.dk Portal for doctors and medical students in Denmark
Pappnase

Post by Pappnase »

hello iascoot

nice hack did you send it also to Oliver? taht he will include it in the next release!?

many greetings to middle earth :wink:
iascoot
Posts: 4
Joined: Sat 28. Feb 2004, 06:16
Location: Dunedin, New Zealand

Post by iascoot »

Hey
Nah i havent submitted it to him yet, I might create another one later on so it doesnt increase if its just a page refresh

ill see what happens tho, anything can happen when you're filled up on energy drinks :P
Post Reply