<!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=gb2312" />
<title>无标题文档</title>
<style>
td{ border:#00C 1px solid;
}
</style>
</head>
<?php
include("conn.php");
?>
<body>
<table style="width:500px; height:30px; border:1px #036 solid; background:#3FF;">
    <?php
     $sql="select * from message";
$query=mysql_query($sql);
while ($row=mysql_fetch_array($query)){
?>
     <tr>
         <td>用户:<?= $row[user]; ?>标题:<?= $row[title]; ?></td>
        </tr> 
        <tr>  
            <td>内容:<?= $row[content];?></td>
        </tr>
        
        <?php
}
?>
    </table>
</body>
</html>-----------------------------------------------------------------------------------------这是conn.php中内容<?php
$conn=@ mysql_connect("localhost","root","") or die ("连接错误");
mysql_select_db("bbs",$conn);
mysql_query("set names 'GBK'");    //使用GBK中文编码
?>

解决方案 »

  1.   

    改用<?php echo 变量?>
    试试
      

  2.   

    下面是php代码:
    <!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=gb2312" />
    <title>无标题文档</title>
    <style>
    td{ border:#00C 1px solid; 
    }
    </style>
    </head>
    <?php
    $conn=@ mysql_connect("localhost","root","") or die ("连接错误");
    mysql_select_db("bbs",$conn);
    mysql_query("set names 'GBK'"); //使用GBK中文编码 
    ?>
    <body>
    <table style="width:500px; height:30px; border:1px #036 solid; background:#3FF;">
      <?php
      $sql="select * from message";
    $query=mysql_query($sql);
    while ($row=mysql_fetch_array($query)){
    echo "
      <tr>
      <td>用户:$row[user] 标题:$row[title]</td>
      </tr>  
      <tr>   
      <td>内容:$row[content]</td>
      </tr>
        
    ";
    }
    ?>
      </table>
    </body>
    </html>下面是数据库,拷贝到sql里面运行:
    CREATE TABLE IF NOT EXISTS `message` (
      `user` varchar(10) NOT NULL,
      `title` varchar(10) NOT NULL,
      `content` varchar(10) NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=gbk;INSERT INTO `message` (`user`, `title`, `content`) VALUES
    ('我', '无', '佛相'),
    ('佛', '无我', '相');