Skip to content

Instantly share code, notes, and snippets.

@RSquaredSoftware
Created April 16, 2012 03:24
Show Gist options
  • Save RSquaredSoftware/2396214 to your computer and use it in GitHub Desktop.
Save RSquaredSoftware/2396214 to your computer and use it in GitHub Desktop.
<?php
Class lotto{
require('File.Class.php');
function init(){
$dbName = lotto;
try {
$dbh = new PDO('mysql:localhost:3306', 'root', '');
}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
//create the database
try{
$sth = $dbh->prepare("CREATE DATABASE IF NOT EXISTS $dbName");
$sth->execute();
}
catch (PDOException $e) {
die("Creating Database Error: ". $e->getMessage());
}
//create the pick3 table
try{
$dbh->exec("USE $dbName;");
$dbh->exec("CREATE TABLE IF NOT EXISTS pick3 (
date DATE NOT NULL,
pick3 INT(3),
PRIMARY KEY (date));");
}
catch (PDOException $e) {
die("Creating Table Error: ". $e->getMessage());
}
//create the pick4 table
try{
$dbh->exec("USE $dbName;");
$dbh->exec("CREATE TABLE IF NOT EXISTS pick4 (
date DATE NOT NULL,
pick3 INT(4),
PRIMARY KEY (date));");
}
catch (PDOException $e) {
die("Creating Table Error: ". $e->getMessage());
}
//create the mega table
try{
$dbh->exec("USE $dbName;");
$dbh->exec("CREATE TABLE IF NOT EXISTS mega (
date DATE NOT NULL,
b1 INT(2),
b2 INT(2),
b3 INT(2),
b4 INT(2),
b5 INT(2),
mb INT(2),
mp INT(1),
PRIMARY KEY (date));");
}
catch (PDOException $e) {
die("Creating Table Error: ". $e->getMessage());
}
//create the powerball table
try{
$dbh->exec("USE $dbName;");
$dbh->exec("CREATE TABLE IF NOT EXISTS powerball (
date DATE NOT NULL,
b1 INT(2),
b2 INT(2),
b3 INT(2),
b4 INT(2),
b5 INT(2),
pb INT(2),
pp INT(1),
PRIMARY KEY (date));");
}
catch (PDOException $e) {
die("Creating Table Error: ". $e->getMessage());
}
//create the classic ohio table
try{
$dbh->exec("USE $dbName;");
$dbh->exec("CREATE TABLE IF NOT EXISTS classic (
date DATE NOT NULL,
b1 INT(2),
b2 INT(2),
b3 INT(2),
b4 INT(2),
b5 INT(2),
b6 INT(2),
PRIMARY KEY (date));");
}
catch (PDOException $e) {
die("Creating Table Error: ". $e->getMessage());
}
//create the ten-OH table
try{
$dbh->exec("USE $dbName;");
$dbh->exec("CREATE TABLE IF NOT EXISTS tenoh (
date DATE NOT NULL,
db1 INT(2),
db2 INT(2),
db3 INT(2),
db4 INT(2),
db5 INT(2),
db6 INT(2),
db7 INT(2),
db8 INT(2),
db9 INT(2),
db10 INT(2),
db11 INT(2),
db12 INT(2),
db13 INT(2),
db14 INT(2),
db15 INT(2),
db16 INT(2),
db17 INT(2),
db18 INT(2),
db19 INT(2),
db20 INT(2),
nb1 INT(2),
nb2 INT(2),
nb3 INT(2),
nb4 INT(2),
nb5 INT(2),
nb6 INT(2),
nb7 INT(2),
nb8 INT(2),
nb9 INT(2),
nb10 INT(2),
nb11 INT(2),
nb12 INT(2),
nb13 INT(2),
nb14 INT(2),
nb15 INT(2),
nb16 INT(2),
nb17 INT(2),
nb18 INT(2),
nb19 INT(2),
nb20 INT(2),
PRIMARY KEY (date));");
}
catch (PDOException $e) {
die("Creating Table Error: ". $e->getMessage());
}
//create the rolling cash 5 table
try{
$dbh->exec("USE $dbName;");
$dbh->exec("CREATE TABLE IF NOT EXISTS rollingfive (
date DATE NOT NULL,
b1 INT(2),
b2 INT(2),
b3 INT(2),
b4 INT(2),
b5 INT(2),
PRIMARY KEY (date));");
}
catch (PDOException $e) {
die("Creating Table Error: ". $e->getMessage());
}
}
function printpick3(){
$dbName = lotto;
//create a PDO object to interface with the database
try {
$dbh = new PDO('mysql:localhost:3306', 'root', '');
}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
if (isset($_GET['date']))
$datesort = !$_GET['date'];
else
$datesort = 'TRUE';
if($datesort)
$sort = 'DESC';
else
$sort = 'ASC';
try{
$dbh->exec("USE $dbName;");
$sth = $dbh->prepare("SELECT * FROM pick3 ORDER BY date $sort");
$sth->execute();
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
}
catch (PDOException $e) {
die("Printing Data Error: ". $e->getMessage());
}
echo '<link href="common/style.css" rel="stylesheet" type="text/css" />';
echo "<table><tr><th><a name=date href='?date=".$datesort."'>Date</a></th><th><a name=nums href='#'>Pick 3</a></th><th></th></tr>";
foreach($result as $r){
echo "<tr><td>".$r[date]."</td><td>".$r[pick3]."</td>";}
echo "</table>";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment