-
-
Save evanpurkhiser/2403025 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require('File.Class.php'); | |
Class lotto{ | |
public 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()); | |
} | |
} | |
public function printpick3(){ | |
$dbName = "lotto"; | |
//create a PDO object to interface with the database | |
try { | |
$dbh = new PDO('mysql:localhost:3306', 'root', '6148914178'); | |
} | |
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 "<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>"; | |
} | |
public function parse($filename) | |
{ | |
// Get the rows of data | |
$data = array_map('trim', explode("\n", file_get_contents($filename))); | |
// array('date' => array('pick1' => val, 'pick2' => val, ...)) | |
$picks = array(); | |
// Get the names of each of the different picks | |
$pick_names = array_slice(explode(',', array_shift($data)), 1); | |
foreach ($data as $pick_row) | |
{ | |
$pick_data = explode(',', $pick_row); | |
// Get the date the picks happend | |
$date = array_shift($pick_data); | |
// Combine the pick data and pick names into an assoicative array. | |
// Also use array filter to ignore empty values | |
$values = array_filter(array_combine($pick_names, $pick_data)); | |
// If there are NO picks for this date, just skip it | |
if (empty($values)) | |
continue; | |
// Add the date to the array with the pick name and value | |
$picks[$date] = $values; | |
} | |
return $picks; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment