为什么我PHP和html混编老是出错,网上找了很久也没有这方面的教程。混编的时候,各种标签该放什么位置一直没搞明白。先看代码:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title>totest
</title>
<style>
#table {
width:1000px;
border-bottom: 1px solid #CCC;
font: small;
}
#td {
border:1px solid #999;
}
.contentcss {
width:150px;
max-height: 2000px;
float:left;
}
.headimg {
width:80%;
height: 50%;
margin: 10px 18px;
text-align: center;
background-color: #CCC;
}
</style>
</head>
<body>
<table id="table" style="margin: 30px 0px 0px 50px">
  <?php
include 'conn.php';
$result = mysql_query("select * from test");
while ($row=mysql_fetch_array($result))
  {
?>
  <tr>
    <td width="751">标题:<?echo $row['title'] ?></td>
    <td colspan="2" style="text-align:right" height="35px"><?echo $row['id'] ?>楼</td>
  </tr>
  <tr>
    <td colspan="3" height="50px">
    <div class="contentcss">
       <div class="headimg">
         <p>头像</p>
         <p>上传</p>
</div>
       <div align="center"><?echo $row['name']?></div>
    </div><?echo $row['content'] ?></td>
  </tr>
  <tr>
    <td>来源:<?echo $row['addfrom'] ?></td>
    <td width="169" style="text-align:right"><?echo $row['datetime'] ?></td>
    <td width="64"><div align="right"><a href="#">回复</a></div></td>
  </tr>
  <?
  }
?>
<form action="add.php" method="post">
标题: <input type="text" name="title" /><br />
文本: <textarea name="content" rows="10" cols="50"/></textarea><br />
来源: <input type="text" name="addfrom" /><br />
作者: <input type="text" name="addauthor" /><br />
<input type="submit" value="发表"/><input type="reset" value="重置" />
</form>
<hr />
</table>
</body>
</html>为什么回复的内容跑上边去了???而且每个回复下面的横线也没有跟着循环???搞了2个小时了,头都大了....www.8cor.com

解决方案 »

  1.   

    为什么回复的内容跑上边去了?
    你是指回复用的表单位置不对吗?你的表单在 </tr> 与 </table> 之间
    也就是在表格之外,表单出现时,表格还未结束,自然就先显示表单再显示表格罗
    你的 <hr /> 在循环之外,怎么能 跟着循环 ?
      

  2.   

    html没学好
      

  3.   

    你的SQL  没有排序另外 不要使用短标记
      

  4.   

    有php的地方用<??>括起来
      

  5.   

    正在学php。学习学习。
      

  6.   

    先好好研究下html
    php是放到 <?php  里面的 ?>
    如果你用dw编辑器。看颜色分辨了。
    至于你说的跑偏问题是 html的问题。
    你看看 css 以及其他。
      

  7.   

    <?echo ?>这样写不好你的代码出错了
    把表单也放到<tr><td>  </td></tr>里
    或者把表单放到表格外面还有你说的横线的问题
    </form>
    <hr />
    </table>
    你应该把他放到循环里面
    要不然他出来才真的神奇你这段 正确的应该是这样的
    <table id="table" style="margin: 30px 0px 0px 50px">
    <?php
    include 'conn.php';
    $result = mysql_query("select * from test");
    while ($row=mysql_fetch_array($result))
    {
    ?>
      <tr>
      <td width="751">标题:<?echo $row['title'] ?></td>
      <td colspan="2" style="text-align:right" height="35px"><?echo $row['id'] ?>楼</td>
      </tr>
      <tr>
      <td colspan="3" height="50px">
      <div class="contentcss">
      <div class="headimg">
      <p>头像</p>
      <p>上传</p>
    </div>
      <div align="center"><?echo $row['name']?></div>
      </div><?echo $row['content'] ?></td>
      </tr>
      <tr>
      <td>来源:<?echo $row['addfrom'] ?></td>
      <td width="169" style="text-align:right"><?echo $row['datetime'] ?></td>
      <td width="64"><div align="right"><a href="#">回复</a></div></td>
      </tr>
      <hr />
      <?
    }
    ?>
    <tr>
    <td>
    <form action="add.php" method="post">
    标题: <input type="text" name="title" /><br />
    文本: <textarea name="content" rows="10" cols="50"/></textarea><br />
    来源: <input type="text" name="addfrom" /><br />
    作者: <input type="text" name="addauthor" /><br />
    <input type="submit" value="发表"/><input type="reset" value="重置" />
    </form>
    </td>
    </tr>
    </table>
      

  8.   

    对的,表格设计的问题。多写写html 就知道了。
      

  9.   

    你最好下载一个dw cs5 然后用他的兼容性测试  把你每次写好的 文件测试下兼容性
      

  10.   

    提高你的html代码的质量
      

  11.   

    PHP是脚本语言,其实和JS嵌套在HTML中的原理是一样的,最终浏览器解析出来的是HTML,PHP部分是由APACHE解析的,这样理解就可以了,还有楼上的说的好,不要使用<? ?>这种短标签
      

  12.   

    如果可以的话,不要用混排吧,用smarty来分离php和html代码,这样写起来会轻松很多!