PHP
  Home arrow PHP arrow Page 3 - Making Usage Statistics in PHP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Making Usage Statistics in PHP
By: Adam Szanto
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 121
    2004-02-16

    Table of Contents:
  • Making Usage Statistics in PHP
  • Save the HTML Title
  • Showing the Statistics Table
  • Showing Figures Based on the Statistics
  • Creating the Image Library
  • Charting the Results
  • Before Saying Goodbye

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Making Usage Statistics in PHP - Showing the Statistics Table


    (Page 3 of 7 )

    Our next task is to code the site that will show us the saved statistics from the database. I will show two examples. The first one is text-based. Its goal is to allow you to review your visitors and visited sites. It's simple and quite obvious so you can get the data that you need from it.

    This page consists of two tables. The first table shows all your visitors, each row represents a user. Data is retrieved from the database, using the MySQL GROUP BY clause. The table has the following columns:

    1. Hostname
    2. Number of visited pages
    3. Clear data from this hostname

    visitors

     

     

     

    The picture above is my solution on my personal homepage. The 'X' signs in the last column are links referring to the code that deletes all visits from the given visitor. The code below shows the first table.


       $q='SELECT Host, COUNT(Site) AS cs FROM hits GROUP BY Host';
       $visitor_r
    =mysql_query($q) or print(mysql_error());
     
       echo 
    "<h3>Visitors</h3><table width=100% border=1><tr>n".
           
    "<td><b>Hostname</td>n".
           
    "<td><b>Visited pages</td>n".
           
    "<td align=center><b>Clear all from this visitor</td></tr>n";
     
       while (
    $visitor=mysql_fetch_array($visitor_r))
          
    echo "<tr><td>".$visitor['Host']."</td>n".
              
    "<td>".$visitor['cs']."</td>n".
              
    "<td align=center><a href=?op=stat&delhost=".
                   urlencode
    ($visitor['Host']).">X</a></td></tr>";
                        
    // This link is to delete the visited pages of this user
                        // Note urlencode() which is because the string
                        // that will be queried as an URL
     
       
    echo "</table>";



    The second table shows all the page impressions, directly from the database. Columns are:

    1. Visited page
    2. Hostname
    3. Date

    page impression

     

     

     

     

    Clicking on the visitor's hostname in the table above clears the data, like the previous query (the links refer to the same piece of code).

    In the first column there is the title of the HTML, but it's a link using the saved URL.

    And now let's see the code for the second table:


       $q='SELECT Title, Site, Host, Date FROM hits
              ORDER BY Date DESC, Host'
    ;
       $page_imp_r
    =mysql_query($q) or print(mysql_error());
     
       echo 
    "<h3>Page impressions</h3>".
           
    "<table width=100% border=1><tr>n".
           
    "<td><b>Visited page</td>n".
           
    "<td><b>Hostname</td>n".
           
    "<td><b>Date</td></tr>n";
     
       while (
    $page_imp=mysql_fetch_array($page_imp_r))
           
    echo "<tr><td><a href=?".$page_imp['Site'].">".
            $page_imp
    ['Title']."</a></td>n".
          
    // Link to the page
            "<td><a href=?op=stat&delhost=".$page_imp['Host'].">".
            $page_imp['Host']."</a></td>n".
             "<td>".$page_imp['Date']."</td></tr>";
    echo "</table>";



    More PHP Articles
    More By Adam Szanto


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT