本文介紹了mysqli 查詢結果顯示所有行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有以下代碼:
include $_SERVER['DOCUMENT_ROOT'].'/include/conn.php';
$query = "SELECT title FROM news_event";
$result = $mysqli->query($query);
$row = $result->fetch_array(MYSQLI_BOTH);
$row_cnt = $result->num_rows;
$result->free();
$mysqli->close();
如果只有一個結果,這很好,因為我可以只回顯 $row['title']
但如果有很多結果,我如何讓它循環并打印每個排?
This is fine if there is only one result as I can just echo $row['title']
but if there are lots of results, how do I get this to loop through and print every row?
我確定這真的很簡單,但我不確定我需要在 Google 中搜索什么.
I'm sure this is really simple but I'm just not sure what I need to search for in Google.
我正在尋找與此等效的 mysqli
:
I'm looking for a mysqli
equivalent of this:
while( $row = mysql_fetch_array($result) )
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br />";
}
推薦答案
只需將其替換為 mysqli_fetch_array
或 mysqli_result::fetch_array
:)
Just replace it with mysqli_fetch_array
or mysqli_result::fetch_array
:)
while( $row = $result->fetch_array() )
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br />";
}
幾乎所有的mysql_*
函數都有對應的mysqli_*
函數.
Almost all mysql_*
functions have a corresponding mysqli_*
function.
這篇關于mysqli 查詢結果顯示所有行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!