Main Menu

HOME

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

US Job listings




   Misc

   Amazon

   Links

    


Lottery draw MySQL and PHP example

 Overview

In this example we will show how to create a basic Lottery number displayer that will show the last 5 numbers picked from the UK National lottery.

This will be the first of our examples which will show some php and MySQL examples.


 

Database Structure and CSV file download

OK the location for the csv file is National lottery site . This file contains 10 fields which are as follows date of the draw, ball numbers 1 to 6, bonus ball number, ball set and name of machine used.

First of all you have to create a database called lotto, in this database create a table call this lotto also. The MySQL dump below shows the structure of this database more clearly.

# phpMyAdmin SQL Dump
# version 2.5.6-rc1
# http://www.phpmyadmin.net
#
# Host: localhost
# Generation Time: Feb 09, 2004 at 04:50 PM
# Server version: 4.0.15
# PHP Version: 4.2.3
#
# Database : `lotto`
#

# --------------------------------------------------------

#
# Table structure for table `lotto`
#

CREATE TABLE `lotto` (
`date` date NOT NULL default '0000-00-00',
`ball1` tinyint(4) NOT NULL default '0',
`ball2` tinyint(4) NOT NULL default '0',
`ball3` tinyint(4) NOT NULL default '0',
`ball4` tinyint(4) NOT NULL default '0',
`ball5` tinyint(4) NOT NULL default '0',
`ball6` tinyint(4) NOT NULL default '0',
`bonus` tinyint(4) NOT NULL default '0',
`ballset` tinyint(4) NOT NULL default '0',
`machine` varchar(20) NOT NULL default '',
KEY `date` (`date`)
) TYPE=MyISAM;

 


 

Modifying the data in the CSV file

Open up the downloaded CSV file and delete all of the column headings on row 1, delete the 1 on row 3, delete the row of minus signs ----- on row 4. Navigate to the bottom of the file and delete the line that says the amount of rows.

Now all that has to be done is get the date format to show correctly. Select column A, right click and select Format Cells from the menu that appears. Now select Date and use English (United KIngdom) as the locale. Now select the Type as 2003-02-01. The column will now change to the proper formatting.

If this is to difficult we have a file with a SQL dump here


 

 Include File

For these examples we are showing you the first step to code re-use, the small file below contains usernames, passwords etc for our database. Now we are going to have several examples so rather that putting the same code in the scripts numerous times we make a seperate script and include that in the scripts using the require_once statement . this has an advantage lets say you changed any of your information in the database like the username, if you had 10 different scripts accessing this information that would be 10 changes but by having a seperate file containing the information this only requires 1 change. Much easier.

Here is the script which we have called dbvariables.php

<?php
//edit these variables below to your own settings
$server = "localhost";
$username = "username";
$password = "password";
$database = "lotto";
//connect to server with username and password
$connection = mysql_connect ($server,"$username", "$password") or die ("Cannot make the connection");
//connect to database
$db = mysql_select_db ($database,$connection) or die ("Cannot connect to database");
?>


 

 Individual Examples

Displaying the last 5 winning lottery draws
 
 
 
 
 
 
 

 



   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
Creating a table in a MySQL database(PHP)
Random number(ASP.net)
open default browser with a url(VB)
Get the names of all processes on your machine(C Sharp)
Replace a word(ASP)
start excel(Powershell)
display service info in a formatted word document(VBScript)
List owners of a process(VBScript)

    




Copyright © 2004 by programmershelp.co.uk