再写list.php时遇到以下几个问题及解决方法:
问题一 : 开始的时候未能正确使用sql语句 ,导致网页一直提示这样的错误 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in E:\wamp\wamp\www\liuyanbanban\list.php on line9
解决方法:在sql语句执行的语句后面添写or die(mysql_error());这样就可以显示出错误出现在哪里,以便于改正
即sql执行语句写成:mysql_query($sql)or die(mysql_error());
问题二: 我的list网页中始终显示不出来用户,标题,内容等信息
解决方法:<?= $row[title]?>改为<?php echo $row['title']?> 可以根据自己所用书写代码的软件性能来定。
我电脑上装的是notepad++ 对于<?php ?>必须要带php,否则会提示错误
对于中括号里面的内容,一般要带单引号,否则很可能会出现错误,在我看来不具有确定性,可以多尝试一下,比如可以用双引号括起来,最终目的是让程序运行正确。
我的代码:list.php
<meta charset="UTF-8">
<?php
include("conn.php");
include("head.php");
$sql="select * from `message` by id desc";
$query=mysql_query($sql);
//or die(mysql_error());
while($row=mysql_fetch_array($query)){
?>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<tr bgcolor="#eff3ff">
<td>标题:<?php echo $row['title']?> 用户:<?php echo $row['user']?> </td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?php
echo htmlcode($row['content']);
?>
</tr>
</table>
<?php
}
?>