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

查看:60
本文介绍了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:)

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天全站免登陆