<?php
/*
* Created on 2009-8-25
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
include("conn.php");?>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef"><?php
   $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>内容:<?=$row["content"]?></td>
  </tr>
  <?php
   }
  ?>
</table>
以上代码运行后,不显示字段内容,为什麽?数据库中有数据,数据库中有少条记录,就显示多少条空记录

解决方案 »

  1.   

    <?=$row[title]?>这些字段名称和数据库的字段名称是否一致呢?
      

  2.   

    如果只是显示“标题”“用户”“内容”的话,而没显示数据库里的记录,我想应该不是这个代码的问题,是那个Post没传记录过来,建议你看下那段代码
      

  3.   

      while($row=mysql_fetch_array($query)) 
      {
        print_r($row);看看输出什么,写程序要学会怎么调试
      

  4.   

    用print_r($row); 显示的内容
    Array ( [0] => 1 [id] => 1 [1] => 11 [user] => 11 [2] => 11 [title] => 11 [3] => 11 [content] => 11 [4] => 2009-08-25 [lastdate] => 2009-08-25 ) Array ( [0] => 2 [id] => 2 [1] => sf [user] => sf [2] => sdf [title] => sdf [3] => sdf [content] => sdf [4] => 2009-08-25 [lastdate] => 2009-08-25 ) Array ( [0] => 3 [id] => 3 [1] => sdfsf [user] => sdfsf [2] => sdfsdf [title] => sdfsdf [3] => sgadfgsdfg [content] => sgadfgsdfg [4] => 2009-08-25 [lastdate] => 2009-08-25 ) Array ( [0] => 4 [id] => 4 [1] => ggg [user] => ggg [2] => gggg [title] => gggg [3] => ggggggggg [content] => ggggggggg [4] => 2009-08-25 [lastdate] => 2009-08-25 ) Array ( [0] => 5 [id] => 5 [1] => sdfsd [user] => sdfsd [2] => fdsf [title] => fdsf [3] => ssfsdf [content] => ssfsdf [4] => 2009-08-25 [lastdate] => 2009-08-25 ) Array ( [0] => 6 [id] => 6 [1] => sdfs [user] => sdfs [2] => sdfsdf [title] => sdfsdf [3] => sagdasdf [content] => sagdasdf [4] => 2009-08-25 [lastdate] => 2009-08-25 ) Array ( [0] => 7 [id] => 7 [1] => fghd [user] => fghd [2] => fdgh [title] => fdgh [3] => fdghdfgh [content] => fdghdfgh [4] => 2009-08-25 [lastdate] => 2009-08-25 ) Array ( [0] => 8 [id] => 8 [1] => sdaf [user] => sdaf [2] => sadfsa [title] => sadfsa [3] => sdfas [content] => sdfas [4] => 2009-08-25 [lastdate] => 2009-08-25 ) Array ( [0] => 9 [id] => 9 [1] => sdfsaf [user] => sdfsaf [2] => sdfsa [title] => sdfsa [3] => sadfasfd [content] => sadfasfd [4] => 2009-08-25 [lastdate] => 2009-08-25 ) Array ( [0] => 10 [id] => 10 [1] => [user] => [2] => [title] => [3] => [content] => [4] => 2009-08-25 [lastdate] => 2009-08-25 ) Array ( [0] => 11 [id] => 11 [1] => ss [user] => ss [2] => ss [title] => ss [3] => fsdfas [content] => fsdfas [4] => 2009-08-26 [lastdate] => 2009-08-26 ) 
      

  5.   

    改成<?=$row[0]?>
    <?=$row[1]?>
    <?=$row[2]?>
    <?=$row[3]?>
    这样的看看
      

  6.   

    这个是张老师的代码,我想问下你那个add。php有没调试成功
    我调试的时候,把$_post种的post变成小写了,结果也是没能显示数据库的内容
    变成大写就可以了,不知道你的是不是跟我一样的错误呢
      

  7.   

    不是add.php好用,只是list.php不好用
      

  8.   

    哪就把<?=$row[title]?>改成<?php echo $row['title']?>吧
      

  9.   

    <?php echo $row["title"]?>  或者<?php echo $row[1]?>
      

  10.   

    你的php配置不支持; Allow the <? tag.  Otherwise, only <?php and <script> tags are recognized.
    ; NOTE: Using short tags should be avoided when developing applications or
    ; libraries that are meant for redistribution, or deployment on PHP
    ; servers which are not under your control, because short tags may not
    ; be supported on the target server. For portable, redistributable code,
    ; be sure not to use short tags.
    short_open_tag = On