我已經將數據靜態存儲在數據庫中。它有5個問題和4個問題。尋求答案。基本上它是一個測驗遊戲格式。現在我想以4列的單選按鈕的形式從數據庫中獲取數據。如何實現該方法。目前我正在以正常文本模式提取。在PHP中以問答遊戲的單選按鈕格式提取數據
下面是代碼
<?php
// Create connection
$conn = new mysqli("localhost","root","","QuizQuestions");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully<br><br>";
$sql = "SELECT Question, Answer1, Answer2, Answer3, Answer4 FROM Questions";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<br>Question: " . $row["Question"]. "<br>";
echo " A) " . $row["Answer1"]. "<br>";
echo " B) " . $row["Answer2"]. "<br>";
echo " C) " . $row["Answer3"]. "<br>";
echo " D) " . $row["Answer4"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
它顯示在下拉列表的形式不是單選按鈕 – LazyLearner
噢,對不起! mybad 2秒我會更新它 –
thanku它的工作,但有一個問題..問題是我提取超過1個問題(一次5問題),所以它只從5個問題中選擇一個 – LazyLearner