mysql_fetch_assoc只获取一条记录 [英] mysql_fetch_assoc fetching only one record

查看:39
本文介绍了mysql_fetch_assoc只获取一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询结果数组:

I have an array with the result of a query:

.....some code.....
$result = mysql_query("SELECT * FROM vttest");
$row = mysql_fetch_assoc($result);
print_r($row);

但是它只打印一条记录,我不能将$ row放入循环中,因为稍后我将继续对该变量进行排序.

But it only prints one record, I can't put $row in a loop because I will be working on sorting that variable later.

Array
(
    [id] => 3
    [rep] => Mike
    [name] => Joe
    [department] => Business
    [location] => Room 1
    [email] => xxxx@hotmail.com
    [phone] => 519-123-4567
    [type] => Visit
    [drink] => Coffee
    [notes] => Some notes
    [lastVisited] => 2010-08-27
    [nextVisit] => 2010-08-27
)

我知道记录比这多得多,如何在仍可以使用$ row变量的情况下打印所有记录?

I know there are more records than that, how can I print all of it while still being able to work with the $row variable?

推荐答案

您实际上正在获取一条记录,因为您需要使用循环来获取所有记录.

You are actually getting one record because you need to use a loop to get all records.:

$my_arary = array();
while($row = mysql_fetch_assoc($result)){
  $my_arary[] = $row;
  print_r($row);
}

如您所说,以后您可以使用$my_arary做任何您想做的事.

As you said, later you can use the $my_arary to do whatever you like.

这篇关于mysql_fetch_assoc只获取一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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