本文介紹了mysqli忽略表中的第一行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
這是我用來從表中提取數據的代碼:
Here is the code I'm using to pull the data from the table:
require_once 'connect.php';
$sql = "SELECT * FROM `db-news`";
$result = $mysqli->query($sql);
$row = mysqli_fetch_assoc($result);
while ($row = $result->fetch_assoc()) {
printf ($row['pagename'].' - To edit this page <a href="editnews.php?id='.$row['id'].'">click here</a><br>');
}
總是忽略第一行.我不會像在 SO 上的其他一些示例那樣調用 mysqli_fetch_assoc
兩次.我已經嘗試在 while 循環中將 echo
更改為 printf
并且仍然忽略數據庫中的第一行.
Always the first row is ignored. I'm not calling mysqli_fetch_assoc
twice as with some other examples on SO. I've tried changing echo
to printf
in the while loop and still the first row is ignored in the DB.
我不知道接下來應該嘗試什么?
I'm at a loss as to what I should try next?
推薦答案
mysqli 沒有忽略它,但實際上你是在 while 循環之前獲取第一行
mysqli not ignoring it but actually you are fetching first row before while loop
$row = mysqli_fetch_assoc($result); //remove this line
while ($row = $result->fetch_assoc()) {
....
}
這篇關于mysqli忽略表中的第一行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!