0

奇妙な一連の出来事。

データベースを構築するために厳密に使用されるWebページがあります(スーパーベアボーン)。HTML フォーム アクションは同じページに対してif(isset($_POST['submit']))行われ、送信ごとにコンテンツを変更する PHP ステートメントを使用します。ユーザーが送信するたびに、 がエコーThis [x] was successfully added.され、ページの下部にテーブルが表示されます。

表には結果が表示されていますが、最初の結果は切り捨てられています。

テーブルのコード:

$host = "x";
$dbusername = "x";
$dbpassword = "x";
$db_name = "x";

mysql_connect("$host","$dbusername","$dbpassword") or die("Cannot connect to database");
mysql_select_db("$db_name") or die("Cannot select database");

// Collect Information
$query = "SELECT * FROM database";

$data = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array($data);

print "<table border='1px' cellpadding='4px' cellspacing='0'><tr><th>ID</th><th>CELL 1</th><th>CELL 2</th><th>CELL 3</th><th>CELL 4</th><th>CELL 5</th><th>CELL 6</th><th>CELL 7</th><th>CELL 8</th><th>CELL 9</th><th>CELL 10</th><th>CELL 11</th><th>CELL 12</th><th>CELL 13</th><th>CELL 14</th></tr>";
while($row = mysql_fetch_array($data)){
    print "<tr><td>";
print $row['index'];
print "</td><td>";
print $row['CELL 1'];
print "</td><td>";
print $row['CELL 2'];
print "</td><td>";
print $row['CELL 3'];
print "</td><td>";
print $row['CELL 4'];
print "</td><td>";
print $row['CELL 5'];
print "</td><td>";
print $row['CELL 6'];
print "</td><td>";
print $row['CELL 7'];
print "</td><td>";
print $row['CELL 8'];
print "</td><td>";
print $row['CELL 9'];
print "</td><td>";
print $row['CELL 10'];
print "</td><td>";
print $row['CELL 11'];
print "</td><td>";
print $row['CELL 12'];
print "</td><td>";
print $row['CELL 13'];
print "</td><td>";
print $row['CELL 14'];
print "</td></tr>";
}

echo "</table>";

mysql_close();

何か案は?

4

1 に答える 1

4

mysql_fetch_array()ループに入る前に呼び出している場合、while ループで再度呼び出すと、結果の最初の行が変数に
ロードされ 、最初の結果行が 2 番目の結果行で上書きされます。$row

$data = mysql_query($query) or die(mysql_error());

**$row = mysql_fetch_array($data);**

print "<table border='1px' cellpadding='4px' cellspacing='0'><tr><th>ID</th><th>CELL 1</th><th>CELL 2</th><th>CELL 3</th><th>CELL 4</th><th>CELL 5</th><th>CELL 6</th><th>CELL 7</th><th>CELL 8</th><th>CELL 9</th><th>CELL 10</th><th>CELL 11</th><th>CELL 12</th><th>CELL 13</th><th>CELL 14</th></tr>";
while($row = mysql_fetch_array($data)){

この行を削除すると、最初の行も表示されます

于 2013-04-12T00:01:16.890 に答える