mysqli query results to show all rows(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 查询结果显示所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:mysqli 查询结果显示所有行


- Laravel 仓库 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01