2012-09-24 139 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 ..,你的意見對我來說非常有用。 –