-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore_json.php
49 lines (42 loc) · 1.18 KB
/
score_json.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
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
$output = $per =$speed = $remark = array();
$mysqli = new mysqli('localhost','root','','gre') ;
//$mysqli->select_db('incapme') or die('cant not select the database');
if(!$mysqli){
echo "{'status':'".$mysqli->connect_errorno()."' }"; ;
exit();
}
$sql = "SELECT * FROM quiz_score ";
$db = $mysqli->query($sql);
if($db){
$i = 1;
while( $result = $db->fetch_array(MYSQLI_ASSOC) ){
$per[0][] = array(0=>$i,1=>$result['percentage']);
$speed[0][] = array(0=>$i,1=>$result['speed']);
$remark[] = $result['remark'];
$i++;
}
}
//sorting remarks
sort($remark);
$sql = "SELECT AVG(percentage) as avg from quiz_score";
$db = $mysqli->query($sql);
$result = $db->fetch_array(MYSQLI_ASSOC) ;
$per_avg = $result['avg'];
$sql = "SELECT AVG(speed) as avg from quiz_score";
$db = $mysqli->query($sql);
$result = $db->fetch_array(MYSQLI_ASSOC) ;
$speed_avg = $result['avg'];
$mysqli->close();
$output = array('per'=>$per,
'speed'=>$speed,
'speed_avg'=>$speed_avg,
'per_avg'=>$per_avg,
'remark'=>$remark
);
echo json_encode($output);
?>