$rawboxscoreurl = "http://gd2.mlb.com/components/game/mlb/year_{$year}/month_{$month}/day_{$day}/gid_{$year}_{$month}_{$day}_{$away_code}mlb_{$home_code}mlb_1/rawboxscore.xml";
//echo $rawboxscoreurl;
$rawboxscorecontents = file_get_contents($rawboxscoreurl);
// Have to skip if game hasn't started yet
$rawboxscorenotavail= (substr($rawboxscorecontents,0,23) == "GameDay - 404 Not Found");
if ($rawboxscorenotavail) {
//echo "\nNo highlights yet";
} else { // otherwise print the top boxscore
$rawboxscore = simplexml_load_string($rawboxscorecontents);
echo '<table><tr>';
// loop through each inning and print the scores
foreach($rawboxscore -> linescore -> inning_line_score as $abc) {
echo '<td><table>';
echo '<tr><td style="border-bottom:solid #ff0000">' . $abc -> attributes() -> inning . '</td></tr>';
echo '<tr><td>';
if (strlen($abc -> attributes() -> away) > 0) {
echo $abc -> attributes() -> away;
} else {
echo '-';
}
echo '</td></tr>';
echo '<tr><td>';
if (strlen($abc -> attributes() -> home) > 0) {
echo $abc -> attributes() -> home;
} else {
echo '-';
}
echo '</td></tr>';
echo '</table></td>';
}
// and summary stats
echo '<td><table style="border-left:thick double #ff0000">';
echo '<tr><td style="border-bottom:solid #ff0000">R</td></tr>';
echo '<tr><td>' . $rawboxscore -> linescore -> attributes() -> away_team_runs . '</td></tr>';
echo '<tr><td>' . $rawboxscore -> linescore -> attributes() -> home_team_runs . '</td></tr>';
echo '</table></td>';
echo '<td><table>';
echo '<tr><td style="border-bottom:solid #ff0000">H</td></tr>';
echo '<tr><td>' . $rawboxscore -> linescore -> attributes() -> away_team_hits . '</td></tr>';
echo '<tr><td>' . $rawboxscore -> linescore -> attributes() -> home_team_hits . '</td></tr>';
echo '</table></td>';
echo '<td><table>';
echo '<tr><td style="border-bottom:solid #ff0000">E</td></tr>';
echo '<tr><td>' . $rawboxscore -> linescore -> attributes() -> away_team_errors. '</td></tr>';
echo '<tr><td>' . $rawboxscore -> linescore -> attributes() -> home_team_errors. '</td></tr>';
echo '</table></td>';
// finish boxscore
echo '</tr></table>';
}
It doesn't look very good with the border I gave it, but I'm having trouble getting HTML borders that look good. Below the highlights I added the list of scoring plays from the inning/inning_Scores.xml page, which was pretty easy because I copied the format of the linescore. Then the boxscore below it has only the batting stats for now, and looks terrible.
At the suggestion of someone else, I made the cursor into an arrow when hovering over the different games and highlight names. This will make is clearer that clicking on them does something. This was done with a single line added to the CSS file
.scorestablegame { cursor:pointer; }
However, I just launched it and, while the scoring plays are showing up, the cursor is still what it was before. I will need to look into this and see why it isn't working.
The tables need a lot of work to make them look better but it is a good start. I also realized that nowhere is the winner/loser/saver listed, this could be added by the boxscore at the bottom or in the scores table on the left. For the latter I can just add the name of the winner and loser next to their team score and it would be fairly easy.
Check it out here: http://honus-1064.appspot.com/.
No comments:
Post a Comment