-1

我基本上有一个输入系统,人们在其中输入数据,数据以特定顺序打印在 HTML 表中。

我有一些代码在下面可以正常工作,除了每次更新行时,都会编辑表而不是添加一个包含数据的新表。另外当我刷新数据时消失了?

我的代码如下:

     $query = "SELECT * FROM rumours";
        $query = mysql_query($query) or die('MySQL Query Error: ' . mysql_error( $connect ));
        while ($row = mysql_fetch_assoc($query)) {
                        $id = $row['id'];
                        $band = $row['band'];
                        $title = $row['Title'];
                        $description = $row['description'];
                         }
$sql="INSERT INTO rumours (band, Title, description)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if (!mysql_query($sql,$connect))
  {
  die('Error: ' . mysql_error());
  }
 if (mysql_query($sql, $connect)) {
echo "<table border='1'>";
echo "<tr>";
echo "<td> $title  </td>";
echo "</tr>";
echo "<tr>";
echo "<td class = 'td1'> $description </td>";
echo "</tr>";
echo "</table>";
    }
echo "1 record added";

mysql_close($connect);
4

1 回答 1

0

您仅从插入的 db 行生成表,而不是 db 表中的所有 db 行。为此,您还必须echo为每个找到的行提供表格代码:

$query = "SELECT * FROM rumours";
$query = mysql_query($query) or die('MySQL Query Error: ' . mysql_error( $connect ));
while ($row = mysql_fetch_assoc($query)) {
  $id = $row['id'];
  $band = $row['band'];
  $title = $row['Title'];
  $description = $row['description'];
  echo "<table border='1'>";
  echo "<tr>";
  echo "<td> $title  </td>";
  echo "</tr>";
  echo "<tr>";
  echo "<td class = 'td1'> $description </td>";
  echo "</tr>";
  echo "</table>";
}
$sql="INSERT INTO rumours (band, Title, description)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
/* ... Code truncated to save space */
于 2012-10-08T20:17:23.650 回答