-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fe1d66
commit 38b97af
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,38 @@ | ||
<?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(); | ||
?> | ||
|