嘿我想用php mysql_fetch_array一次获取全表数据
while($user_details_result[]=mysql_fetch_assoc($user_details_qr));
但它最后返回一个空白数组,如下面的
输出:
Array
(
[0] => Array
(
[user_id] => 2
[user_name] => w
[user_login_id] => w
[user_login_password] => w
[user_contacts] => w
[user_status] => 0
[user_post_date] => ::1
[user_post_ip] => 2014-03-07 16:17:59
)
[1] => Array
(
[user_id] => 1
[user_name] => q
[user_login_id] => q
[user_login_password] => q
[user_contacts] => q
[user_status] => 1
[user_post_date] => ::1
[user_post_ip] => 2014-03-07 16:14:23
)
[2] =>
)
我不明白为什么会出现第3行..请帮助
答案 0 :(得分:1)
使用此
while($temp=mysql_fetch_assoc($user_details_qr)) {
user_details_result[] = $temp;
}
答案 1 :(得分:0)
mysql_fetch_assoc
将返回FALSE
。如果您将FALSE
写入$user_details_result[]
,那么它将成为一个空白数组。
http://us1.php.net/manual/function.mysql-fetch-assoc.php
试试这个
while($cur_row=mysql_fetch_assoc($user_details_qr)) {
if($cur_row !== FALSE) { $user_details_result[] = $cur_row; }
}
但我认为它甚至可以在没有if
的情况下工作,就像这样(测试它):
while($cur_row=mysql_fetch_assoc($user_details_qr)) {
$user_details_result[] = $cur_row;
}
答案 2 :(得分:0)
尝试使用像这样的
while($row=mysql_fetch_assoc($user_details_qr))
{
if (count($row) > 0)
$user_details_result[] = $row;
}