<?php
$mysql_db = mysql_connect("localhost","root","root");
@mysql_select_db("test",$mysql_db);
$result = mysql_query("select * from user where name = '张三'");
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo $row['name'];
}
?>
提示错误如下:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\www\test\user01.php on line 13
$mysql_db = mysql_connect("localhost","root","root");
@mysql_select_db("test",$mysql_db);
$result = mysql_query("select * from user where name = '张三'");
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo $row['name'];
}
?>
提示错误如下:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\www\test\user01.php on line 13
表中数据如下:
id name tel educational date
5 张四 020-5566556 中专毕业 2006-10-15
3 张三 13612312331 本科毕业 2006-10-15
1 张三 13333663366 大专毕业 2006-10-11
4 王五 13521212125 大专毕业 2006-12-25
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<?php
$mysql_db = mysql_connect("localhost","root","root");
mysql_select_db("test",$mysql_db);
$result = mysql_query("select * from user where name = '张三'");
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo $row['id'].''.$row['name'];
}
?>
</body>
</html>去掉了以后报错如下:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\www\test\user01.php on line 13
<?php
$mysql_db = mysql_connect("localhost","root","root");
mysql_select_db("test",$mysql_db);
mysql_query("set names 'gbk'"); //增加这个代码试试看,可能是编码问题导致你查询不到结果
$result = mysql_query("select * from user where name = '张三'");
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo $row['id'].''.$row['name'];
}
?>