2013-04-11 51 views
0

奇數系列事件。截斷第一個結果的SQL結果

我有一個嚴格用於構建數據庫(超級準系統)的網頁。 HTML表單操作是在同一頁面 - 用PHP語句if(isset($_POST['submit']))來更改每次提交的內容。用戶每次提交時,都會回顯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

你打電話mysql_fetch_array()之前,你進入循環
加載了結果的第一行到$row變量
在while循環再次調用它,你覆蓋第一個結果行與第二個

$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)){ 

刪除此行,它會顯示第一行以及