-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_question.php
38 lines (27 loc) · 899 Bytes
/
fetch_question.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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "question_db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$question_id = 1; // You can change this to fetch different questions
$question_sql = "SELECT * FROM questions WHERE id = $question_id";
$question_result = $conn->query($question_sql);
$options_sql = "SELECT * FROM options WHERE question_id = $question_id";
$options_result = $conn->query($options_sql);
$response = array();
if ($question_result->num_rows > 0) {
$response['question'] = $question_result->fetch_assoc();
}
if ($options_result->num_rows > 0) {
$response['options'] = array();
while($row = $options_result->fetch_assoc()) {
$response['options'][] = $row;
}
}
echo json_encode($response);
$conn->close();
?>