这段php代码有什么问题?
这是我用来查看论坛内容的简单 php 代码。问题是,它在我的一台笔记本电脑上工作正常,但在第二台笔记本电脑上它不显示输出。
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td bgcolor="#E6E6E6"><? echo $rows['id']; ?></td>
<td bgcolor="#E6E6E6"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#E6E6E6"><? echo $rows['view']; ?></td>
<td align="center" bgcolor="#E6E6E6"><? echo $rows['reply']; ?></td>
<td align="center" bgcolor="#E6E6E6"><? echo $rows['datetime']; ?></td>
</tr>
我检查了其他一切,它们看起来都很好。数据存在于数据库中,但未显示在论坛中。有人可以帮我吗? 操作系统:win7
This the simple php code I am using to view contents of a forum. The problem is , it's working fine in one of my laptop but in second it do not show the output.
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td>
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td>
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td bgcolor="#E6E6E6"><? echo $rows['id']; ?></td>
<td bgcolor="#E6E6E6"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#E6E6E6"><? echo $rows['view']; ?></td>
<td align="center" bgcolor="#E6E6E6"><? echo $rows['reply']; ?></td>
<td align="center" bgcolor="#E6E6E6"><? echo $rows['datetime']; ?></td>
</tr>
I checked everything else and they seems fine. Data is present in the database but the it's not showing in forum. Can anybody help me in this?
operating sys : win7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是时候学习调试了,朋友。
好的起点: http://www.ibm.com/developerworks/library/os -debug/
对于 mysql,以这种方式运行查询非常方便:
并确保您可以看到发生的所有错误。
如果您不能快速修复,您可以在脚本顶部添加这些行
,但对于生产状态
display_errors
值应更改为 0检查 HTML 源代码而不是在浏览器中观看渲染的页面。它会告诉您短标签是否有任何问题。在解决问题之前知道是否有任何问题总是好的。
time to learn debugging, pal.
Good place to start: http://www.ibm.com/developerworks/library/os-debug/
for mysql it's extremely handy to run queries this way:
and make sure you can see all errors occurred.
if you can't as a quick fix you can add these lines at the top of the script
but for the production state
display_errors
value should be changed to 0It is also good practice to check HTML source instead of watching rendered page in the browser. It will tell you if you have any problem with short tags or not. It's always good to know if you have any problem before going to fix it.
你应该使用
而不是
短标签可能被禁用。
you should use
<?php echo $rows['id']; ?>
instead of<? echo $rows['id']; ?>
short tag may be disabled.