php中通过查询将查询到的内容循环到table中,可是table 中不显示任何内容,这是为什么呢,以下是我的代码,麻烦哪位大侠看看什么地方写的有问题
<?php
include_once '../dbCon.php';
$db = new DbCon();
$conn = $db->getConn();//或得数据库连接
$sql = 'select * from t_message';
$result = mysql_query($sql);
print_r(mysql_fetch_array($result));//能够取到数据库中的数据
?>
<table>
<tr>
<th>留言內容</th>
<th>留言時間</th>
</tr>
<?
while($row = mysql_fetch_array($result)){
echo 'test';//没有输出;
print_r($row['user_id']);//没有输出
?>
<tr>
<td><? echo$row['message']?></td>
<td><? echo$row['time']?></td>
</tr>
</table>
<?
}
?>
<?php
include_once '../dbCon.php';
$db = new DbCon();
$conn = $db->getConn();//或得数据库连接
$sql = 'select * from t_message';
$result = mysql_query($sql);
print_r(mysql_fetch_array($result));//能够取到数据库中的数据
?>
<table>
<tr>
<th>留言內容</th>
<th>留言時間</th>
</tr>
<?
while($row = mysql_fetch_array($result)){
echo 'test';//没有输出;
print_r($row['user_id']);//没有输出
?>
<tr>
<td><? echo$row['message']?></td>
<td><? echo$row['time']?></td>
</tr>
</table>
<?
}
?>
<td><? echo$row['message']?></td>
<td><? echo$row['time']?></td>
</tr>
<?
}
?></table>你该补补HTML知识
echo 后面空格
这里是不是已经取走了?
1、</table>标签不能放到循环体。
2、echo输出内容时,注意有空格。===========================
你首先要保证循环体有循环执行,然后再去修改输出内容和格式。
print_r(mysql_fetch_array($result));//能够取到数据库中的数据,循环体就该有内容输出$result = mysql_query($sql);
//print_r(mysql_fetch_array($result));//能够取到数据库中的数据
?>
<table>
<tr>
<th>留言內容</th>
<th>留言時間</th>
</tr>
<?
while($row = mysql_fetch_array($result)){
echo 'test';//没有输出;
//print_r($row['user_id']);//没有输出
?>
<?
}
?>
</table>