PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
  Classes of Matthew Boyle  >  PHP NBA API and MLB Stats  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: PHP NBA API and MLB Stats
Retrieve statistics from NBA and MLB API
Author: By
Last change:
Date: 8 months ago
Size: 2,064 bytes
 

Contents

Class file image Download
<?
error_reporting
(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors',true);

echo
'<html>
<body>'
;

if(
$_SERVER['REQUEST_METHOD'] != 'POST' )
{
   
// form
?>
<style>
td {
    border: 1px solid #000;
}
td:first-child {
    text-align: right;
}
td label {
    padding-right: 10px;
    font-weight: bold;
}
td input,
td select {
    margin-left: 5px;
}
</style>
The form below can request teams or standing* for either sport which don't require an API token.<br />
It can also request data that does require a token. If you have a valid token you may edit this file to utilize it.<br /><br />
* standings will require a token if a date is specified.
<form method="post">
<table>
    <tr>
        <td><label for="sport">Sport:</label></td>
        <td><select name="sport" id="sport">
            <option value="">Both / None</option>
            <option value="mlb">MLB Baseball</option>
            <option value="nba">NBA Basketball</option>
        </select></td>
    </tr><tr>
        <td><label for="endpoint">Information:</label></td>
        <td><select name="endpoint" id="endpoint">
            <option value="me">API account</option>
            <option value="events">Events</option>
            <option value="standings">Standings</option>
            <option value="leaders">Leaders</option>
            <option value="boxscore">Box Score</option>
        </select></td>
    </tr><tr>
        <td><label for="date">Date:</label></td>
        <td><input name="date" id="date" type="text" placeholder="YYYYmmdd" /></td>
    </tr><tr>
        <td><label for="id" title="team_id, event_id, category_id">ID:</label></td>
        <td><input name="id" id="id" type="text" /></td>
    </tr>
</table>
<br />
<input type="submit" value="Submit" />
</form>
<?
}
else
{
    include(
'XMLstats/xmlstats.class.php');

   
$stats = new XMLstats();
   
$params = [];
    foreach(
$_POST as $k => $v){
        if(
$k != 'endpoint' && !empty($v))
           
$params[$k] = $v;
    }
   
$data = $stats->getData($_POST['endpoint'],$params);

   
$arr = json_decode($data,1);
   
$arr['headers'] = $stats->getResponseHeader();

    echo
'<pre>'. print_r($arr, 1) .'</pre>';
}
?>
</body>
</html>