0

我有一个由 php 循环在表中生成的表单。除了生成的第一个表单外,该表单工作正常。我似乎无法弄清楚为什么。这是我的代码,我是否错过了某个地方的关闭?

    while($row = mysql_fetch_array($result))
      {
      $msisdn = $row['msisdn'];
      $messageid = $row['messageid'];
      echo "<tr>";
      echo "<td style='width:70px;'><center>" . $row['message-timestamp'] . "</td>";
      echo "<td><center>" . $row['terpname'] . "</td>";
      echo "<td>";
      echo "<div class='layer1'>
            <p class='heading'><B><U><font size='2' color='blue'>Reply</font></u></b> </p>
            <div class='content'>
            <fieldset >
            <form name='reply' method='post' action='reply.php'>
            <textarea rows='4' cols='50' name='response' value=''></textarea>
            <input type='hidden' name='phonenumber' value='$msisdn' /><BR>
            <input type='hidden' name='messageid' value='$messageid' /><BR>
            <input type='submit' name='search' class='btn btn-info btn-large'  value='Send' />
            </form>
            </fieldset>
            </div>
            </div>
            ";
      echo "-->" . $row['text'];
      //Select responses to this text message
      $sqlselect = "SELECT * FROM li_appointments.li_outbound_sms
            where messageid = '" . $row['messageid'] . "';";
      $subresult = mysql_query($sqlselect);

      //Loop through results and display them
      while($row = mysql_fetch_array($subresult))
            {
            echo "<BR><--" . $row['sender'] . "(" . $row['datetime'] . "): " . $row['message'];
            }
      echo "</td>";     
      echo "<td style='width:10px;'><center><input type='checkbox' class='db'          onclick='resetSelectAlldb();'name='database[]', value='$messageid'></center></td>";
      echo "</tr>";
      }
4

1 回答 1

0

你应该使用准备语句,但无论如何你不能在同一个函数中使用 $row 两次。

   while($row = mysql_fetch_array($result))
  {
  $msisdn = $row['msisdn'];
  $messageid = $row['messageid'];
  echo "<tr>";
  echo "<td style='width:70px;'><center>" . $row['message-timestamp'] . "</td>";
  echo "<td><center>" . $row['terpname'] . "</td>";
  echo "<td>";
  echo "<div class='layer1'>
        <p class='heading'><B><U><font size='2' color='blue'>Reply</font></u></b> </p>
        <div class='content'>
        <fieldset >
        <form name='reply' method='post' action='reply.php'>
        <textarea rows='4' cols='50' name='response' value=''></textarea>
        <input type='hidden' name='phonenumber' value='$msisdn' /><BR>
        <input type='hidden' name='messageid' value='$messageid' /><BR>
        <input type='submit' name='search' class='btn btn-info btn-large'  value='Send' />
        </form>
        </fieldset>
        </div>
        </div>
        ";
  echo "-->" . $row['text'];
  //Select responses to this text message
  $sqlselect = "SELECT * FROM li_appointments.li_outbound_sms
        where messageid = '" . $row['messageid'] . "';";
  $subresult = mysql_query($sqlselect);

  //Loop through results and display them
  while($row2 = mysql_fetch_array($subresult))
        {
        echo "<BR><--" . $row2['sender'] . "(" . $row2['datetime'] . "): " . $row2['message'];
        }
  echo "</td>";     
  echo "<td style='width:10px;'><center><input type='checkbox' class='db'          onclick='resetSelectAlldb();'name='database[]', value='$messageid'></center></td>";
  echo "</tr>";
  }
于 2013-08-06T20:48:00.583 回答