0

重複の可能性:
phpでmysqlクエリを行ごとに反復する方法

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>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</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>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
4

1 に答える 1

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>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<?php
}
?>

while() loop考えられるすべての答えを繰り返すために使用する必要があります。

于 2012-09-24T05:29:27.193 に答える