Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Make money selling software. Check this out here

Hosted clickbank mall. Check this out here




   Misc

   Amazon

   Links

    


MySQL counter

 

In this tutorial / code example we will show you how to build a simple counter using a MySQL database . This database will be called counter , it will contain one table called counter which will in turn contain one field called count.

Start MySQL and at the command prompt type the following

CREATE database counter;
USE counter;

CREATE table counter(count int(10) DEFAULT '0' NOT NULL);

This creates our MySQL database . Now for the script to access the count and display this on our web page.

Replace hostname , username and password with your own details

<?php

//make a connection
$connection = mysql_connect("hostname","username" ,"password")
or die ("Cannot make that connection");
//connect to our database
$db = mysql_selectdb("counter" , $connection);
//store the result of the query in $result
$result = mysql_query("SELECT * FROM counter");
//retrieve the fields in our table
$fields = mysql_fetch_row($result);
//update the count field by 1
mysql_query("UPDATE counter SET count = count+1");
//$mycount variable is set to the first field (count)
$mycount = $fields[0];
//display the count
echo $mycount;
?>

 

 

 

 

 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
alter text properties(Darkbasic)
search an array(php)
Display the filesystem of a drive(VB)
Random numbers in a range(C)
Math co-processor(C)
get the Windows XP product serial number(C Sharp)
DAtabase example(ASP.net)
Last accessed time of a file(Powershell)

    




Copyright © 2003 by programmershelp.co.uk