PHP Custom Web Statistics – Part 2

In the second part of this tutorial about creating your own custom web statistics, we analyse the data that is collected each time a page is viewed. We'll be looking at various ways of reading the data we require from the database, and making MySQL work harder by using some of its extra functions to process our data.

We create a function to execute an SQL query, so that we don't repeatedly enter code to open and close the database etc, which makes for shorter code that’s easier to understand and debug. We then create a range of functions that could extract certain statistics from the data stored in the database. We create a set of functions which create the SQL queries dynamically, and can be easily inserted into the framework of the main site pages.

We then construct a page which serves as the index page for the web statistics application, and shows an overall view of every year that has data in the database, showing each year and the number of hits per month.

Finally, we create a page that displays a single year's-worth of data at a time, in a table which is dynamically generated using PHP, and shows more detailed figures for the year.

 

Please note that this article forms part of a chapter in the DMXzone e-book PHP Web Applications for Dreamweaver: Juicy Solutions for the Busy Developer.

 

$2.79
- OR -

Overview

Table of Content:

  • Working with MySQL Data
  • Creating a new include file - dbFunctions.php
  • Creating Data Retrieval Functions
    • dataHitsByYear() - Return number of Hits per Year
    • dataHitsByMonth() - Returns hits per month for a given year
    • dataHitsByWeek() - Returns number of hits for each week of a given year
    • dataPagesPerMonth - Returns the total number of unique pages served per month
    • dataUniqueVisitorsPerMonth - Returns the number of Unique Visitors per Month
  • Creating the Main Web Statistics Page
    • Adding the PHP Code
  • Creating the Year Statistics Page - year.php
  • Summary

Gareth Downes-Powell

Gareth Downes-PowellGareth has a range of skills, covering many computer and internet related subjects. He is proficient in many different languages including ASP and PHP, and is responsible for the setup and maintenance of both Windows and Linux servers on a daily basis.


In his daily web development work he uses the complete range of Macromedia software, including Dreamweaver MX, Flash MX, Fireworks MX and Director to build a number of websites and applications. Gareth has a close relationship with Macromedia, and as a member of Team Macromedia Dreamweaver, he has worked closely in the development of Dreamweaver, and was a beta tester for Dreamweaver MX.


On a daily basis he provides support for users in the Macromedia forums, answering questions and providing help on a range of different web related subjects. He has also written a number of free and commercial extensions for Dreamweaver MX, to further extend its capabilities using its native JavaScript API’s or C++.


As a web host, Gareth has worked with a range of different servers and operating systems, with the Linux OS as his personal favourite. Most of his development work is done using a combination of Linux, Apache and MySQL and he has written extensively about setting up this type of system, and also running Apache and MySQL under Windows.

See All Postings From Gareth Downes-Powell >>

Reviews

Be the first to write a review

You must me logged in to write a review.