2013-04-02 41 views
1

我正在使用mysql_fetch_query()創建數組,然後使用while函數打印數據庫中的一個表,從而打印數據庫中的某個表中的所有數據。從數據庫中的表中打印數據

唯一的是,它正在跳過第一條記錄並直接打印記錄2.記錄1確實存在於表中,並且被命名爲這樣。

有什麼我失蹤或需要添加?

mysql_connect("$host", "$username", "$db_password")or die("cannot connect"); 

$data=mysql_query("SELECT * FROM users")or die(mysql_error()); 
$info=mysql_fetch_array($data); 
while($info = mysql_fetch_array($data)){ 
    echo "<br />"; 
    echo "Record id: <strong>" . $info['id'] . "</strong>"; 
    echo "<br />"; 
    echo "Visit time and date: <strong>" . $info['visitDate'] . "</strong>";  
    echo "<br />"; 
    echo "Previous destination: <strong>" . $info['cameFrom'] . "</strong>"; 
    echo "<br />"; 
    echo "Browser used: <strong>" . $info['browser'] . "</strong>"; 
    echo "<br />"; 
    echo "Location of user: <strong>" . $info['location'] . "</strong>"; 
    echo "<p> </p>"; 
} 
+0

擺脫第一個'$ info = mysql_fetch_array($ data);'行。 – Passerby

回答

1
$info=mysql_fetch_array($data); 
while($info = mysql_fetch_array($data)){ 

只留下了條件,因爲你讓一個循環,這是第一個船長行之前

2

while循環之前刪除此行:

$info=mysql_fetch_array($data); 

這將獲取的第一條記錄,而當你開始while循環是從第二排開始,因爲你再打電話mysql_fetch_array()

+0

現在我明白了啊 –

0

你叫mysql_fetch_array()兩次取

**$info=mysql_fetch_array($data); 
while($info = mysql_fetch_array($data))** 

所以你的第一個記錄已經被第一次打電話給mysql_fetch_array()

只是刪除第一個電話,它會正常工作。