mysqli 查询结果显示所有行 [英] mysqli query results to show all rows

查看:25
本文介绍了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_arraymysqli_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 查询结果显示所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆