[php]代码库
<?php
require('./include/init.php');//调用配置文件
//配合foreach输出所有帖子
$sql = 'select * from thread order by pubtime desc'; // 如果不明白此句,请看燕十八mysql视频
$list = getAll($sql,$conn);
//比较笨的统计回帖数方法
foreach($list as $k=>$v) {
$sql = 'select count(*) from reply where tid=' .$v['tid'];
$list[$k]['rnum'] = getOne($sql,$conn);
}
/*
* 这是用1条sql语句来完成的,供大家参考
* $sql = 'select *,(select count(*) from reply where reply.tid=thread.tid) as rnum from thread order by pubtime desc';
* $list = getAll($sql,$conn);
*/
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script type="text/javascript">
</script>
<style type="text/css">
</style>
</head>
<body>
<table border="1">
<tr>
<td>姓名</td>
<td>标题</td>
<td>内容</td>
<td>发帖时间</td>
<td>回帖数</td>
</tr>
<?php
foreach($list as $v)
{
echo '<tr>';
echo '<td>',$v['username'],'</a></td>';
echo '<td><a href="tie.php?tid=',$v['tid'],'">',$v['title'],'</a></td>';
echo '<td>',$v['content'],'</a></td>';
echo '<td>',date('Y-m-d H:i:s',$v['pubtime']),'</a></td>';
echo '<td>',$v['rnum'],'</a></td>';
echo '</tr>';
}
?>
</table>
<form action="pubaction.php" method="post">
usename:<input type="text" name="username" /><br />
title:<input type="text" name="title" /><br />
content:<textarea name="content" ></textarea> <br />
<input type="submit" value="提交修改" />
</form>
</body>
</html>