Home  >  Article  >  Backend Development  >  PHP从mysql中读取多条数据输出遇到问题

PHP从mysql中读取多条数据输出遇到问题

WBOY
WBOYOriginal
2016-06-23 13:50:31966browse

语句大约是这样的
$sql="select * from team where number between 50 and 60";
res=mysql_query($sql);
while($row=mysql_fetch_array($res))
{
echo $row["name"];
}


我很纳闷,执行这个程序的时候使用CMD执行的,后来我发现while语句没有执行
求大神指教这是为什么
而且为什么直接echo $row的话显示的是Array字样呢?
PHP小白真心求教。
望大神赐教


回复讨论(解决方案)

$res= mysql_query($sql   ,  数据库连接资源);
虽然第二个值不是必须的,但是你的while无法执行,明显while为假。可能是获取不到数据库数据。

$row 本来就是数组,echo 不输出Array,输出什么。

echo $row的话显示的是Array字样是因为 $row是一个数组。

改成这样看看,应该可以列出查询的记录。

$sql="select * from team where number between 50 and 60";$res=mysql_query($sql);$result = array();while($row=mysql_fetch_array($res)){$result[] = $row;}print_r($result);

Statement:
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