<?php
/*
* Created on 2010-9-6
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
include ("dblink.php");
?>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?
$sql="select * from message";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
?>
<tr bgcolor="#eff3ff">
<td>标题:<?=$row[title];?> 用户:<?=$row[user]?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?php echo $row[content];?></td>
</tr>
<?
}
?>
</table>大家帮忙看一下 为什么从数据库中 没有读出数据!!! 谢谢啦!!!
这个SQL语句放在数据库中有输出数据吗?
改成:
$row=mysql_fetch_assoc($query) 或者 $row=mysql_fetch_array($query, MYSQL_ASSOC)程序后面
<td>标题:<?=$row[title];?> 用户:<?=$row[user]?></td>
用$row= mysql_fetch_object($result);
$row->username;读取数据
你可以先查询出来结果总数看有多少行数据
select count(*)...
$row[0];看下有没有数据 $row["username"]读取数据加上双引号 另外最好用htmlentities()转换下
这文章适合你
将独立的 <? 改成 <?php 即可
/*
* Created on 2010-9-6
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
include ("include.php");
?>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?php
$sql="select * from xin";
$query=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($query)){
$a=$row[id];
$b=$row[name];
$c=$row[content];
?>
<tr bgcolor="#eff3ff">
<td>标题:<?php echo $a;?> 用户:<?php echo $b?></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?php echo $c;?></td>
</tr>
<?php
}
?>
</table>
你把对应的内容改成你的就可以了
主要是<?的问题,要<?php
在混合html的标记里面 一定要写php
应该少了单引号试一下
<td>标题:<?=$row['title'];?> 用户:<?=$row['user']?></td>