-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
349 lines (255 loc) · 9.14 KB
/
index.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<html lang='en'>
<head>
<title>cs218</title>
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<!-- // <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js" ></script> -->
</head>
<body>
<header>
<nav class="navbar navbar-default" role="navigation">
<?php
require_once('./dbpw.php'); //holds login cridentials for mysql database
/*looks like
class dbpw
{
public static $hostname;
public static $database;
public static $username;
public static $password;
}*/
class db extends dbpw
{
public static function connect()
{
$db_server = mysql_connect(self::$hostname, self::$username, self::$password); //loging onto server with error cheching
if (!$db_server) die("unable to connect to server!" .mysql_error());
// echo "connected to db <br/> ---------------------------------- <br/>";
mysql_select_db(self::$database)
or die("unable to select database! " . mysql_error());
// echo "database selected <br/>-----------------------------------<br/>";
return $db_server;
}
public static function close($db)//just a shorthand for closing db
{
mysql_close($db);
}
public static function query($query)//not very creative but should do the trick
{
$db = self::connect();
$results= mysql_query($query);
if($results)
return $results;
else
echo "bad query!" . mysql_error();
}
public static function buildHtmlTable($titles, $results)
{
$table="<table class='table table-striped'";
$a=mysql_fetch_assoc($results);
if(sizeof($titles)!=sizeof($a))
die("your number of titles and colums do not match!\n");
else
{
$x=sizeof($titles);
$table.="<tr>";
for ($i=0; $i < $x; $i++)
{
$table.="<th>".$titles[$i]."</th>";
}
$table.="</tr>";
do
{
$table.="<tr>";
foreach ($a as $value) {
$table.="<td>$value</td>";
}
$table.="</tr>";
} while($a=mysql_fetch_assoc($results));
$table.="</table>";
return $table;
}
}
}
$program = new program();
class program {
function __construct() {
$page = isset($_POST['mode']) ? $_POST['mode'] : isset($_REQUEST['page'])? $_REQUEST['page'] : "home";
// $arg = $_REQUEST['arg'];
$page = new $page();
}
function __destruct() {
}
}
//base page element
abstract class page
{ //classname => link name
protected $menu = array('home' => 'Home' , 'q1' => 'q1','q2' => 'q2',
'q3' => 'q3','q5' => 'q5','q6' => 'q6','q7' => 'q7',
'q8' => 'q8','q9' => 'q9','q10' => 'q10','q11' => 'q11','q12' => 'q12' );
protected $page ="<div class='container'>";
function __construct()
{
$tmpIndex = array_search($this->name, array_keys($this->menu));
array_splice($this->menu, $tmpIndex, 1);
$this->buildMenu();
}
protected function buildMenu()
{
$tmpMenu='<ul class ="nav navbar-nav">';
foreach ($this->menu as $k => $v) //grabbing array_keys and value
{
$tmpMenu.= "<li><a href='?page=$k'>$v</a></li>";
}
$tmpMenu.='</ul></nav></header>';
echo $tmpMenu;
}
function __destruct()
{
$this->page.='</div>';//close our container
echo $this->page;
}
}
class home extends page
{
public $name='home';
function __destruct()
{
$this->page.='<p>Welcome to my home page</p>';
page::__destruct();
}
}
class q1 extends page
{
public $name='q1';
//Create a web page that shows the colleges that have the highest enrollment
function __destruct()
{
$query="select schools.INSTNM, enrolment.EFYTOTLE, enrolment.YEAR FROM enrolment ".
" join schools on enrolment.UNITID=schools.UNITID "
. " order by enrolment.EFYTOTLE desc limit 10;";
$titles=["School","Enrolment", "Year"];
$results=db::query($query);
$this->page.=db::buildHtmlTable($titles,$results);
//$this->page.=print_r(mysql_fetch_assoc($results));
page::__destruct();
}
}
class q2 extends page
{
public $name='q2';
function __destruct()
{
$query="select schools.INSTNM, stats.LIABILITIES, stats.YEAR ".
"from stats join schools on stats.UNITID = schools.UNITID ".
"order by LIABILITIES desc limit 10;";
$titles=["School","Liabilities", "Year"];
$results=db::query($query);
$this->page.=db::buildHtmlTable($titles,$results);
page::__destruct();
}
}
class q3 extends page
{
public $name='q3';
function __destruct()
{
$query="select schools.INSTNM, enrolment.EFYTOTLE, enrolment.YEAR FROM enrolment join schools on enrolment.UNITID=schools.UNITID order by enrolment.EFYTOTLE desc limit 10;";
$titles=["School","Assets", "Year"];
$results=db::query($query);
$this->page.=db::buildHtmlTable($titles,$results);
page::__destruct();
}
}
class q5 extends page
{
public $name='q5';
function __destruct()
{
$query="select schools.INSTNM, stats.TOTALREV, stats.YEAR from stats join schools on stats.UNITID = schools.UNITID order by stats.TOTALREV desc limit 10;";
$titles=["School","Revenues", "Year"];
$results=db::query($query);
$this->page.=db::buildHtmlTable($titles,$results);
page::__destruct();
}
}
class q6 extends page
{
public $name='q6';
function __destruct()
{
$query = "select schools.INSTNM, stats.TOTALREV/ enrolment.EFYTOTLE as REVPER, stats.YEAR FROM stats join schools on stats.UNITID = schools.UNITID join enrolment on stats.UNITID = enrolment.UNITID where stats.YEAR= enrolment.YEAR order by REVPER desc limit 10;";
$titles=["School","Revenues Per Student", "Year"];
$results=db::query($query);
$this->page.=db::buildHtmlTable($titles,$results);
page::__destruct();
}
}
class q7 extends page
{
public $name='p7';
function __destruct()
{
$query="select schools.INSTNM, stats.NETASSET/ enrolment.EFYTOTLE as ASSETPER, stats.YEAR FROM stats join schools on stats.UNITID = schools.UNITID join enrolment on stats.UNITID = enrolment.UNITID where stats.YEAR= enrolment.YEAR order by ASSETPER desc limit 10;";
$titles=["School","Assets Per Student", "Year"];
$results=db::query($query);
$this->page.=db::buildHtmlTable($titles,$results);
page::__destruct();
}
}
class q8 extends page
{
public $name='q8';
function __destruct()
{
$query="select schools.INSTNM, stats.LIABILITIES/ enrolment.EFYTOTLE as LIABPER, stats.YEAR FROM stats join schools on stats.UNITID = schools.UNITID join enrolment on stats.UNITID = enrolment.UNITID where stats.YEAR= enrolment.YEAR ORDER BY LIABPER DESC limit 10;";
$titles=["School","Liabilities Per Student", "Year"];
$results=db::query($query);
$this->page.=db::buildHtmlTable($titles,$results);
page::__destruct();
}
}
class q9 extends page
{
public $name='q9';
function __destruct()
{
$this->page.="<p>this is where $this->name should be</p>";
page::__destruct();
}
}
class q10 extends page
{
public $name='q10';
function __destruct()
{
$this->page.="<p>this is where $this->name should be</p>";
page::__destruct();
}
}
class q11 extends page
{
public $name='q11';
function __destruct()
{
$query="select schools.INSTNM, a.LIABILITIES as liabilities, a.YEAR as year ,b.LIABILITIES, b.YEAR, ((b.LIABILITIES-a.LIABILITIES)/a.LIABILITIES)*100 AS DIFF from stats a INNER join schools on a.UNITID= schools.UNITID inner join stats b on a.UNITID=b.UNITID WHERE a.YEAR=2010 AND b.YEAR=2011 ORDER BY DIFF DESC limit 10;";
$titles=["School","\$Liabilities", "Year", "\$Liabilities", "Year", "%Increase"];
$results=db::query($query);
$this->page.=db::buildHtmlTable($titles,$results);
page::__destruct();
}
}
class q12 extends page
{
public $name='q12';
function __destruct()
{
$query="select schools.INSTNM, a.EFYTOTLE as efytotle, a.YEAR AS year, b.EFYTOTLE, b.YEAR, ((b.EFYTOTLE-a.EFYTOTLE)/a.EFYTOTLE)*100 AS DIFF FROM enrolment a inner join schools on a.UNITID= schools.UNITID inner join enrolment b on a.UNITID=b.UNITID WHERE a.YEAR=2010 AND b.YEAR=2011 ORDER BY DIFF DESC limit 10;";
$titles=["School","Students", "Year", "Students", "Year", "%Increase"];
$results=db::query($query);
$this->page.=db::buildHtmlTable($titles,$results);
page::__destruct();
}
}
?>
</body>
</html>