Skip to content

Commit

Permalink
Update fetch_question.php
Browse files Browse the repository at this point in the history
  • Loading branch information
mah-shamim authored Jul 27, 2024
1 parent 0fe1d66 commit 38b97af
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions fetch_question.php
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();
?>

0 comments on commit 38b97af

Please sign in to comment.