有关mysql_fetch_object($sql)的数组有关问题

WBOY
Release: 2016-06-13 13:38:01
Original
943 people have browsed it

有关mysql_fetch_object($sql)的数组问题
$conn=mysql_connect("localhost","root","")or die("数据库服务器连接错误".mysql_error());
  mysql_select_db("xuanke",$conn)or die("数据库访问错误".mysql_error());
  mysql_query("set names gb2312");
  $sql=mysql_query("SELECT course_id FROM `info_selected` WHERE stu_id");
  while($r=mysql_fetch_object($sql)) {
  $row[] = $r;
  }
  $sum=count($row);
  echo $sum;
  echo $row[0];
  mysql_free_result($sql);
  mysql_close($conn);
高手指点下,上述程序中的$row是个数组吗?为何echo $sum;能够正常输出结果而echo $row[0];却显示错误呢?
如果$row不是数组,该如何依次输出其中的值呢?

------解决方案--------------------
你不看手册的吗?

mysql_fetch_object返回的是对象
大多数对象可用 foreach 遍历
------解决方案--------------------

探讨

while($r=mysql_fetch_object($sql)) {
$row[] = $r;
}
我觉着这一句应该是将返回的对象放到一个数组里吧!我希望能有什么方法可以将数组里的值依次输出

------解决方案--------------------
你说的显示错误是指什么呢? 循环之后你print_r($row); 看看。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template