forked from rgdalessandro/ipohype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.php
72 lines (52 loc) · 1.54 KB
/
control.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
include_once("connection.php");
switch ($_GET['function']) // switch statement to determine function to run
{
case "dateToCheck":
dateToCheck();
break;
case "monthToCheck":
monthToCheck();
break;
case "dateExists":
dateExists();
break;
}
function dateToCheck() // function to retrieve from SQL all IPOs on a given date
{
$date = date('Y-m-d', strtotime($_GET['date']));
$sql = "SELECT * FROM ipo WHERE ipodate = '" . mysql_escape_string($date) . "' ORDER BY hype DESC";
$con = new connection();
$con->execute($sql);
$ipos = array();
while ($con->fetch())
{
$ipos[] = $con->rows;
}
$json = json_encode(array("results" => $ipos, "status" => "OK"));
die($json);
}
function monthToCheck() // function to retrieve from SQL all IPOs in a given month
{
$month = $_GET['month'];
$year = $_GET['year'];
$sql = "SELECT * FROM ipo WHERE month(ipodate)='" . mysql_escape_string($month) . "' AND year(ipodate)='" . mysql_escape_string($year) . "' ORDER BY ipodate";
$con = new connection();
$con->execute($sql);
$ipos = array();
while ($con->fetch())
{
$ipos[] = $con->rows;
}
$json = json_encode(array("results" => $ipos, "status" => "OK"));
die($json);
}
function dateExists() // function to check if any IPOs exist in the database for a given date
{
$date = date('Y-m-d', strtotime($_GET['date']));
$sql = "SELECT COUNT(*) AS count FROM ipodate WHERE ipodate = '" . mysql_escape_string($date) . "'";
$con = new connection();
$con->execute($sql);
die($con->fetch());
}
?>