mysql_fetch_array 只返回一行 [英] mysql_fetch_array return only one row

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

问题描述

好的,我有以下代码:

$array = mysql_query("SELECT artist FROM directory WHERE artist LIKE 'a%' 
        OR artist LIKE 'b%' 
        OR artist LIKE 'c%'");
    $array_result= mysql_fetch_array($array);

然后,当我尝试回显内容时,我只能回显 $array_result[0];,它输出第一项,但是如果我尝试回显 $array_result[1]; 我得到一个未定义的偏移量.

Then, when I try to echo the contents, I can only echo $array_result[0];, which outputs the first item, but if I try to echo $array_result[1]; I get an undefined offset.

然而,如果我通过 PHPMyAdmin 运行上述查询,它会返回一个包含 10 个项目的列表.为什么这不被识别为 10 个项目的数组,允许我回显 0-9?

Yet if I run the above query through PHPMyAdmin it returns a list of 10 items. Why is this not recognized as an array of 10 items, allowing me to echo 0-9?

感谢您的帮助.

推荐答案

那是因为数组代表返回结果集中的一行.您需要执行mysql_fetch_array() 函数 再次获取下一条记录.示例:

That's because the array represents a single row in the returned result set. You need to execute the mysql_fetch_array() function again to get the next record. Example:

while($data = mysql_fetch_array($array)) {
  //will output all data on each loop.
  var_dump($data);
}

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

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