2012-09-24 108 views
1

我在做关于php的调查问卷,我是php的新手。当我试图展示答案时,它只显示前两个问题。在两个问题后,答案没有显示。我在这里附上了源代码。遍历MySQL表中的列

请使用以下链接查看页面。 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

我的建议是停止使用mysql函数学习PDO ... – Surace

+0

你可以粘贴你的问题和答案表结构吗? – GBD

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

,然后再试一次

+0

我试过这个,还是有同样的问题... –

+1

你有没有试过mysql_query或mysqli_query?我刷新了你给出的链接,它显示mysqli_query的错误。我建议mysql_query.Your表结构仅显示问题ID 1和2的答案,是否有更多记录? – pkachhia

+0

抱歉,所有这些都是我的错误,我的桌子上没有更多记录。感谢pkachhia ..,你的意见对我来说非常有用。 –