我有以下代码:
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模板网!
mysql 中的 store_result() 和 get_result() 返回 falsestore_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
调用未定义的函数 mysqli_result::num_rows()Call to undefined function mysqli_result::num_rows()(调用未定义的函数 mysqli_result::num_rows())
PHP 准备好的语句问题PHP Prepared Statement Problems(PHP 准备好的语句问题)
mysqli_fetch_array 只返回一个结果mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一个结果)
PHP MySQLi 多次插入PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
如何确保 MySQL 中的值在 PHP 中保持其类型?How do I make sure that values from MySQL keep their type in PHP?(如何确保 MySQL 中的值在 PHP 中保持其类型?)