我有以下代码:
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模板网!