为什么我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
<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
你是指回复用的表单位置不对吗?你的表单在 </tr> 与 </table> 之间
也就是在表格之外,表单出现时,表格还未结束,自然就先显示表单再显示表格罗
你的 <hr /> 在循环之外,怎么能 跟着循环 ?
php是放到 <?php 里面的 ?>
如果你用dw编辑器。看颜色分辨了。
至于你说的跑偏问题是 html的问题。
你看看 css 以及其他。
把表单也放到<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>