You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
900 B
42 lines
900 B
<?php
|
|
|
|
$DATAhst="localhost";
|
|
$DATAusr="root";
|
|
$DATApwd="root";
|
|
$DATAdtb="vds";
|
|
|
|
$conn=@mysqli_connect($DATAhst, $DATAusr, $DATApwd, $DATAdtb)or die("CONNECTION ERROR");
|
|
mysqli_set_charset($conn, "utf8");
|
|
|
|
$query="SELECT * FROM questions";
|
|
$q=mysqli_query($conn, $query);
|
|
$data=array();
|
|
$answers=array();
|
|
|
|
class Answer {}
|
|
|
|
while($r=mysqli_fetch_array($q)) {
|
|
|
|
$answers=[];
|
|
$answers_unserializes = unserialize($r['answers']);
|
|
foreach ($answers_unserializes as $key => $value) {
|
|
$answer = new Answer();
|
|
$answer->id = trim($key);
|
|
$answer->text = trim($value);
|
|
if($key == intval($r['correct'])){$answer->correct = true;}
|
|
$answers[] = $answer;
|
|
}
|
|
|
|
$data[] = array(
|
|
"id" => trim($r['id']),
|
|
"question" => trim($r['question']),
|
|
"points" => trim($r['points']),
|
|
"answers" => $answers
|
|
);
|
|
|
|
}
|
|
|
|
header('Content-type: application/json');
|
|
echo json_encode( $data );
|
|
|
|
?>
|