/
getquestions.php
63 lines (48 loc) · 1.64 KB
/
getquestions.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
<?php
// get request parms
$request = "get-questions";
$failed = false;
require_once('config_category.php');
// if database connection failed then return error
if ( $failed ) {
print json_encode($returnVal);
return;
}
if ( !($stmt = $link->prepare("SELECT a.categoryId, a.question, a.id
from questions a
where a.id >= ?
and a.categoryId = ?
order by a.id")
)) {
$returnVal = array( $request, array( "code" => "error", "message" => 'SQL prepare failed. Error: '. $link->error), array() );
print json_encode($returnVal);
return;
}
$stmt->bind_param("ii", $requestId, $requestCategoryId );
// set parameters and execute
//$requestId = $_GET['id'];
// var_dump($_POST);
// return;
$requestId = (int) $_POST['startid'];
$requestCategoryId = (int) $_POST['catid'];
// $requestId = (int) $_GET['id'];
// $requestCategoryId = (int) $_GET['catid'];
if (!($stmt->execute() )) {
$returnVal = array( $request, array( "code" => "error", "message" => 'SQL insert failed. Error: '. $link->error), array() );
print json_encode($returnVal);
return;
}
if (!($stmt->bind_result( $rowCategoryId, $rowQuestion, $rowId )) ) {
echo "bind result failed. error: ".$link->error;
}
// // prepare return object
$returnVal = array( $request, array( "code" => "success", "message" => "success"), array() );
while ( $stmt->fetch() ) {
$returnVal[2][] = array( "id" => $rowId,
"question" => $rowQuestion,
"categoryId" => $rowCategoryId
);
}
// var_dump( json_encode($returnVal) );
print json_encode($returnVal);
?>