Use of PHP & MYSQL to create NFL Football Picks Program


2011 NFL Full Schedule


Written by Chanda


The NFL Schedule data is stored in MySQL database. I loaded the data in PHP arrays. The array game1 has all the 17 weeks' first games data and array game2 has second games data, and so on. In the code, ${$team . $k} will be executed as $game1, $game2, $game3...

Here is the code: (I should have used variables instead of hard-coding number of weeks and number of games):

echo '2011 NFL Full Schedule';
$k=1;
$team='game';
$hteam='hgame';
$gday='dgame';
echo '<table>';
for ($i=0; $i <16; $i++){
echo '<tr>';
if ($i==0){
for ($m=1;$m<18;$m++){
echo '<td>'.'Week '.$m.'</td>';
}
echo '</tr><tr>';
}
for ($j=0;$j<17;$j++) {
echo '<td>';
echo ${$team . $k}[$j];
if ( ${$team . $k}[$j] == "" ) {
echo '--';
} else {
echo '@';
}
echo ${$hteam . $k}[$j];
if ( ${$team . $k}[$j] == "" ) {
echo '--';
} else {
echo ' on ';
}
$str=${$gday . $k}[$j];
echo substr($str,strpos($str,',')+2,strlen($str));
echo '</td>';
}
$k++;
echo '</tr>';
}
echo '</table>';

Execution of the code:


Explanation of the code:

echo substr($str,strpos($str,',')+2,strlen($str));

works with just - echo substr($str,strpos($str,',')+2);


The game days are stored like 'Sun, Oct 23' and only 'Oct 23' is displayed.


2011 NFL Picks


The NFL picks program is written in PHP using MYSQL database: (you can enter your picks and click on submit)


Code explanation:

Game week, game days and team names are retrieved from the database. Game week is displayed based on the current date. Teams are displayed based on the game week. Change in game days are displayed based on simple comparison logic. A portion of the source code:

<?php
$hostname = "hostname";
$username= "username";
$password= "password";
$dbid="database id";
$con=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die ("can not connect to database");
$query1 = "SELECT gweek FROM gameweek where curdate() between gfrom_date and gto_date";
$result1=mysql_query($query1);
$vweek=mysql_result($result1,0,"gweek");
$query = "SELECT * FROM tnflsched where vweek = $vweek";
$result=mysql_query($query);
$game1=mysql_result($result,0,"game1");
$hgame1=mysql_result($result,0,"hgame1");
$dgame1=mysql_result($result,0,"dgame1");
mysql_close($con);
?>
Week <? echo $vweek ?>
<? echo $dgame1 ?>
<? echo $game1 ?><input type="radio" name="game1" id='game1[0]' value="<? echo $game1 ?>" />
<? echo $hgame1 ?><input type="radio" name="game1" id='game1[1]' value="<? echo $hgame1 ?>" />
<?php
if ($dgame1 <> $dgame2) {
echo "$dgame2";
}
?>

$1.99 Website Hosting- Go Daddy Proud Sponsor of Danica Patrick

2011 NFL Results


The code is written in PHP using MySQL. jQuery AJAX is used to load data from the server without a browser page refresh.

A portion of the Code:

<h3>2011 NFL Results</h3>
<p>Pick a week and click on <span style="font-size:120%;font-weight: bold;">Go</span>.</p>
<form action="" method="post">
<table><tr><td><select id="vweek" name="vweek">
<?PHP for($i=0;$i<$count;$i++){ ?>
<option value="<? echo $gameweek[$i] ?>"><? echo $gameweek[$i] ?></option>
<?php } ?>
</select>
</td>
<td><input type="button" name="submit" id="submit" value="Go" onclick="nflresults()"/></td>
</form>


 


Free SEO Tools $1.99 Web Hosting at GoDaddy.com.com

 

Great Deals and Big Savings



Microsoft Expression Studio 4 Web Professional
Microsoft Expression Studio 4 Web Professional


Tapestry Theme - A Tumblog-Style Theme for Wordpress
Tapestry Theme - A Tumblog-Style Theme for Wordpress