遍历MySQL表中的列

时间:2012-09-24 08:40:23

标签: 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

1 个答案:

答案 0 :(得分:0)

替换

$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()");

再试一次