Popular Articles | Latest Articles | Categories | RSS Feeds

Database driven web counter with PHP/mySQL

Published on 6/2/2009 by Dotnetindex
More articles in PHP



 Vote this tutorial:

This simpel script stores page hits on a database file. In every visit, script counts the hits and updates database. To drive this PHP script , you need PHP, mySQL. You may setup script easily, just copy and paste following code into a page.

 

<?php
    $conn = mysql_pconnect('localhost', 'root', 'sorma');
    mysql_select_db('ritimshop');
    /*
    CREATE TABLE IF NOT EXISTS `mycounter` (
    `hit` int(11) default '0'
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8;
    insert into mycounter (hit) values (0);
    */
    mysql_query('update mycounter set hit = hit + 1', $conn) or die(mysql_errno() .":". mysql_error());
    $result = mysql_query("select hit from mycounter", $conn)  or die(mysql_errno() .":". mysql_error());
    $hits = mysql_fetch_array($result, MYSQL_ASSOC);
    echo $hits['hit'];
    mysql_close($conn);
?>

Do not forget to create database table with this SQL script. Run sql script within phpmyadmin:

 

    CREATE TABLE IF NOT EXISTS `mycounter` (
    `hit` int(11) default '0'
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8;
    insert into mycounter (hit) values (0);

 

 

Comments:
no comments submitted


Only members can write comments.Please, login / register to write comment.

Latest Posts

Active News Manager - news management system




Welcome to Dotnetindex.com:Login  |  Register
Free software:
Giga RSS Reader
IkonAdman
QMailing list
Active News
Download Manager (PRO)
Download Manager (Lite)

Search Dotnetindex.com:


Who's online

  • There 17 online users.

Latest tutorialsAutocomplete Filter from the Old Futures Project Working in Dynamic Data 4
Developing a Facebook Connect Application Using ASP.NET
Conditional Row Highlighting in Dynamic Data
UserControl as a DLL Made Easy
Using GroupTemplate in ASP.NET ListView Control (Tiled Display)
Creating Master-Detail GridView Using jQuery
ASP.NET MVC 2.0 and AJAX Part 1
Sorting Tabular Data in ASP.NET MVC
Asynchronous Form in ASP.NET MVC 2
Populating ASP.NET TreeView Control Recursively
A look at SAP Crystal Reports for Visual Studio 2010
Reporting in Threads
Regular Expressions Make Pattern Matching and Data Extraction Easier
Perform Database Administration Operations with SQL Server Management Objects
SQL Server Compact 3.5 Beta 2 available for download
ASP.NET Resources, Reviews

ASP Resources, Reviews

PHP, ASP, .NET, JSP Resources, Reviews

Hotscripts.com Free Photoshop, Flash and 3DS MAX tutorials