-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
40 lines (34 loc) · 1.03 KB
/
api.php
File metadata and controls
40 lines (34 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
// Connect to Database
$link = mysql_connect('mcalearning.com', 'user', 'password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db('sofiav_mathgame', $link);
if (!$db_selected) {
die ('Can\'t access database : ' . mysql_error());
}
//API Functions
//All will create a data "array of arrays" to be turned into JSON and returned
//Note - account verification and multiplayer functionality will be handled by separate PHP scripts
//Get a seed (Returns as 'seed.seed')
if($_GET["id"] == "seed")
{
$rand = rand(0, 33999);
$seedval = mysql_query( "select seed from sofiav_mathgame.seed where seed_id = " . $rand );
$return = array(
array("seed"),
array("seed", $seedval )
);
}
//Return JSON
echo('{"' . $return[0][0] . '"{');
for ($x = 0; $x < sizeof($return)-1; $x++)
{
if($x + 1 < sizeof($return)-1)
echo(' "' . $return[$x][0] . '":"' . $return[$x][1] . '",');
else
echo(' "' . $return[$x][0] . '":"' . $return[$x][1] . '"');
}
echo('}');
?>