关于mysql_fetch_****
今天调试如下代码:
mysql_select_db('content',$link);//选择数据库 mysql_query("set names utf8");//设置编码格式 $q="select * from content";//设置查询指令 $result=mysql_query($q);//执行查询 echo "$result"; while($row=mysql_fetch_assoc($result))//将result结果集中查询结果取出一条
其中:mysql_fetch_assoc就是没有值,就会返回如下结果:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in E:\AppServ\www\liuyanban.php on line 21
类似的还有mysql_fetch_array.等,,都是需要有值返回的!用echo调试,
echo "$变量";
今天的源代码是查看一个mysql的东西然后显示出来.如下;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <center><table style="border:dotted;border-color:#F06"> <caption>留言内容</caption> <tr><th>编号</th><th>用户</th><th>标题</th><th>内容</th><th>发表时间</th></tr> <?php $link=mysql_connect('localhost','root','123456')or die("数据库连接失败"); //连接数据库 mysql_select_db('content',$link);//选择数据库 mysql_query("set names utf8");//设置编码格式 $q="select * from content";//设置查询指令 $result=mysql_query($q);//执行查询 echo "$result"; while($row=mysql_fetch_assoc($result))//将result结果集中查询结果取出一条 { echo"<tr><td>".$row["id"]."</td><td>".$row["username"]."</td><td>".$row["title"]."</td><td>".$row["content"]."</td><td>".$row["lastdate"]."</td><tr>"; } ?> </table> <a href="liuyanban.html">返回</a> </center> </body> </html>
数据库是:
编号 用户 标题 内容 发表时间
1 我的名字 我的标题 我是内容 2014-03-13
2 asdf asdfff fdasfa 2014-03-04
3 ddsfas asdfas ahasdf 2014-03-05
6 sdfggfa asdfqwehy hfdhsdfg 2014-03-06
7 sadf asdf gga 2014-03-02
哈哈,,无聊了哈
作者:叉叉敌
博客:https://chasays.github.io/
微信公众号:Chasays, 欢迎关注一起吹牛逼,也可以加个人微信号「xxd_0225」互吹。
本博客大多为学习笔记或读书笔记,本文如对您有帮助,还请多推荐下此文,如有错误欢迎指正,相互学习,共同进步。