-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.php
50 lines (46 loc) · 1.1 KB
/
tests.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
<?php
class Question {
public $text;
public $order;
public $id;
public $answers;
function __construct($question) {
global $mysqli;
$this->answers = [];
$this->id = $question->id;
$result = $mysqli->query("SELECT * FROM answers WHERE question_id=" . $question->id);
while ($answer = $result->fetch_object()) {
$this->answers[$answer->id] = $answer;
}
$this->text = $question->text;
$this->order = $question->order;
}
}
class Test {
public $id;
public $name;
public $questions;
function __construct($test) {
global $mysqli;
$this->questions = [];
$result = $mysqli->query("SELECT * FROM questions WHERE test_id=" . $test->id);
while ($question = $result->fetch_object()) {
$this->questions[$question->id] = new Question($question);
}
$this->name = $test->name;
$this->id = $test->id;
}
}
class Tests {
public $tests;
function __construct() {
global $mysqli;
$result = $mysqli->query("SELECT * FROM tests");
$this->tests = [];
while ($test = $result->fetch_object()) {
$this->tests[$test->id] = new Test($test);
}
}
}
$tests = new Tests();
$tests = $tests->tests;