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

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

问题描述

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

这将返回

2063:7

我以前没有使用计数,所以我不是100%肯定它不是计数表列。这晚,我可能会疯了。

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>";

它输出:

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

TL; DR:我提交其返回多行查询,但只fetch_array给我的那些行的所得数组中的一小部分。

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 只返回一行在一次你必须使用循环来检索所有的行

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