This repository has been archived by the owner on Nov 11, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathquestionsdata.php
62 lines (53 loc) · 1.63 KB
/
questionsdata.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
<?
require_once('auth.php');
require_once('connect.php');
$page = 1;
$sortname = 'id'; // Sort column
$sortorder = 'asc'; // Sort order
$qtype = ''; // Search column
$query = ''; // Search string
// Get posted data
if (isset($_POST['page'])) {
$page = mysql_real_escape_string($_POST['page']);
}
if (isset($_POST['sortname'])) {
$sortname = mysql_real_escape_string($_POST['sortname']);
}
if (isset($_POST['sortorder'])) {
$sortorder = mysql_real_escape_string($_POST['sortorder']);
}
if (isset($_POST['qtype'])) {
$qtype = mysql_real_escape_string($_POST['qtype']);
}
if (isset($_POST['query'])) {
$query = mysql_real_escape_string($_POST['query']);
}
if (isset($_POST['rp'])) {
$rp = mysql_real_escape_string($_POST['rp']);
}
// Setup sort and search SQL using posted dat
$sortSql = "order by $sortname $sortorder";
$searchSql = ($qtype != '' && $query != '') ? "where $qtype = '$query'" : '';
$sql = "SELECT count(*) FROM question $searchSql";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$total = $row[0];
$pageStart = ($page-1)*$rp;
$limitSql = "limit $pageStart, $rp";
$data = array();
$data["page"] = $page;
$data["total"] = $total;
$data["rows"] = array();
$sql = "SELECT lefttext,text,righttext,enable,id FROM question $searchSql $sortSql $limitSql";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
if ($row['enable'] == 0)
$row['enable'] = 'No';
else
$row['enable'] = "Yes";
$data["rows"][] = array("id" => $row['id'],
"cell" => array($row['lefttext'],$row['text'],$row['righttext'],$row['enable']));
}
echo json_encode($data);
?>