mysql_fetch_array 不检索所有行 [英] mysql_fetch_array does not retrieve all rows

查看:26
本文介绍了mysql_fetch_array 不检索所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$query = "SELECT * FROM table";$result = mysql_query($query, $db);$all = mysql_fetch_assoc($result);回声 mysql_num_rows($result) .":" .计数($全部);

返回

2063:7

我以前没有使用过计数,所以我不能 100% 确定它没有计算表格列.太晚了,我可能要疯了.

这是正在发生的另一个例子:

$result = mysql_query($query, $db);回声行:".mysql_num_rows($result) ." <BR/>";$player_array = mysql_fetch_assoc($result);echo "

";打印_r($player_array);echo "</pre>";

输出:

行:9大批([玩家ID] =>10000030)

TL;DR:我提交了返回多行的查询,但 fetch_array 只给了我结果数组中这些行的一小部分.

解决方案

mysql_fetch_assoc 一旦你必须使用循环来检索所有行,就只返回一行

while($row = mysql_fetch_assoc($result)){打印_r($row);}

$query = "SELECT * FROM table";
$result = mysql_query($query, $db);
$all = mysql_fetch_assoc($result);
echo mysql_num_rows($result) . ":" . count($all);

This returns

2063:7

I have not used count before, so I'm not 100% sure it's not counting the table columns. It's late and I might be going nuts.

Here's another example of what's happening:

$result = mysql_query($query, $db);
echo "Rows: " . mysql_num_rows($result) . " <BR />";

$player_array = mysql_fetch_assoc($result);
echo "<pre>";
print_r($player_array);
echo "</pre>";

Which outputs:

Rows: 9 
Array
(
    [playerID] => 10000030
)

TL;DR: I submit queries which return multiple rows, but fetch_array only gives me a small portion of those rows in the resulting array.

解决方案

mysql_fetch_assoc returns only one row in once you have to use loop to retrieve all rows

while($row = mysql_fetch_assoc($result))
{
   print_r($row);
}

这篇关于mysql_fetch_array 不检索所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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