嗨,我正在創建一個問卷。問題和他們的答案存儲在如下表格中: 在表中每隔一行回顯不同的表列
現在,我想在一個表格中顯示問題及其答案,在表格中我可以在不同的行上得到問題及其可能的答案。像這樣:
在我的PHP文件,我呼應表和行,但我無法弄清楚如何把不同行的問題和答案。這裏是它的樣子:
,這裏是我的PHP代碼:
<?php
session_start();
$status=$_GET["status"];
include 'dbh.inc.php';
?>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
text-align: left;
padding: 8px;
}
#td_box{
text-align: center;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #006689;
color: white;
}
</style>
</head>
<body>
<?php
if ($status=="disp") {
$sql="SELECT * FROM questions";
$result = mysqli_query($conn,$sql);
echo "<table>";
while ($row=mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>"; echo $row["question"]; echo "</td>";
echo "<td>"; echo $row["optionA"];echo $row["optionB"];echo $row["optionC"];
echo $row["optionD"];echo $row["optionE"];echo "</td>";
}
}
echo "</table>";
?>
</body>
</html>
您好,感謝答案。單選按鈕apear但不是文本(同意,不同意等) – jimiss
是的,看看我更新的答案@ jimiss – JYoThI