-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.php
36 lines (33 loc) · 1.5 KB
/
server.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
<?php
session_start();
require_once 'config.php';
$db = new Cl_DBclass();
$user_id = $_SESSION['id'];
$page = $_GET['page']; // obter a página solicitada
$limit = $_GET['rows']; // obter quantas linhas queremos ter na grade
$sidx = $_GET['sidx']; // obter linha de índice - i.e. , clique no usuário para classificar
$sord = $_GET['sord']; // pegue a direção
if(!$sidx) $sidx =1; // conectar-se ao banco de dados
$result = mysqli_query( $db->con, "SELECT COUNT(*) AS count FROM scores where user_id = '$user_id' ");
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/$limit);
//$total_pages = ceil($count/1);
} else {
$total_pages = 0;
} if ($page > $total_pages)
$page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
$SQL = "SELECT S.*, C.category_name from scores S LEFT JOIN categories C ON S.category_id = C.id where S.user_id = '$user_id' ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysqli_query( $db->con, $SQL ) or die("Não foi possível executar a consulta.".mysqli_error($db->con));
$responce = new stdClass();
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$responce->rows[$i]['id']=$row['id'];
$responce->rows[$i]['cell']=array($row['id'],$row['category_name'],$row['right_answer'],$row['wrong_answer'],$row['unanswered']); $i++;
}
echo json_encode($responce);exit;