我需要遍历mysql行。举个例子,如果问题id为1,所有的答案都必须显示在问题1下。我是php的初学者,任何人都可以帮助我吗?
<?php
$result = select("SELECT * FROM questions WHERE question_id=1");
$row = mysql_fetch_array($result);
?>
<table width="581" height="299" border="1">
<tr>
<td>Union Assurance Questionnaire</td>
</tr>
<tr>
<td>1.<?php echo $row['questions']; ?>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<?php
$result = select("SELECT * FROM questions WHERE question_id=2");
$row = mysql_fetch_array($result);
?>
<table width="581" height="299" border="1">
<tr>
<td>2.<?php echo $row['questions']; ?>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
答案 0 :(得分:0)
像这样使用
<?php
while($row = mysql_fetch_array($result))
{
?>
<table width="581" height="299" border="1">
<tr>
<td>Union Assurance Questionnaire</td>
</tr>
<tr>
<td>1.<?php echo $row['questions']; ?>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<?php
}
?>
您必须使用while() loop
来迭代所有可能的答案。