php - 遍历 MySQL 表中的列

标签 php mysql sql

我正在做关于 php 的问卷调查,我是 php 新手。当我尝试显示答案时,它只显示前两个问题。在这两个问题之后,没有显示答案。我在这里附上了来源。

请使用以下链接查看页面。 http://itsupportsrilanka.com/uaquiz/quiz.php

<body>

<form action="test.php" method="POST">


   <?php
            $result = select("SELECT * FROM questions ");
            //$row = mysql_fetch_array($result);


        ?>
<?php
$i=1;
while($row = mysql_fetch_array($result))
{
?>
<table width="581" height="299" border="1">
<tr>
<td>Union Assurance Questionnaire</td>
</tr>
<tr>
<td><?php echo $i.'.' .$row['questions']; ?>
<?php $i++; ?>
</td>
</tr>
<tr>
<td>
<?php $qId=$row['question_id'];

$result1=select("SELECT * FROM answers WHERE questionId='$qId' ORDER BY RAND()");
while($row1=mysql_fetch_array($result1)){

    ?>
    <input type="radio" name="answers" value="<?php echo $row1['answers'];?>" / ><?php echo $row1['answers']; ?><br/>


<?php 
} ?>
&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<?php
}
?>
</form>
</body> 

enter image description here enter image description here

最佳答案

替换

$result = select("SELECT * FROM questions "); with $result = mysql_query("SELECT * FROM questions ");

$result1=select("SELECT * FROM answers WHERE questionId='$qId' ORDER BY RAND()"); with 
$result1=mysql_query("SELECT * FROM answers WHERE questionId='$qId' ORDER BY RAND()");

再试一次

关于php - 遍历 MySQL 表中的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12561487/

相关文章:

php - 如果我想用撇号的文本更新文本区域字段,htmlentities 是否会影响 htmlspecialchars?

mysql - 我如何对大型 mysql 表中的单个列进行低安全性编码,然后反转它?

mysql - 从 mysqldump 导入单个记录

mysql - select * but group by 某列,只针对某列

sql - Oracle 中表达式的返回数据类型

php - Laravel 在电子邮件确认 View 不起作用后立即更改密码

php - 图像 map 坐标悬停与ajax不工作

php - Gzip 压缩的带有 php header 的 css 文件,第一个 css 行不起作用

mysql - 为什么查询优化器不使用表中定义的索引? (mysql)

SQL 示例查询(我的答案正确吗?)