1 开发思路
查询数据:从新闻数据表中的查询全部数据。
显示内容:在模板中显示新闻数据。
2 新闻列表
1)查询数据:创建index.php查询新闻数据
include 'Sql.php';
$conn = connect('root', '123456', 'news', $error);
if (!$conn) {
exit($error);
}
// 新闻列表
$sql = 'SELECT n.*,a.name FROM news n LEFT JOIN author a ON n.a_id=a.id';
$news = read($conn, $sql, $error, true);
include 'add.html';
2)显示内容:通过foreach将查询出来的新闻数据输出到页面中
<?php foreach($news as $n): ?>
<div class="news-list-item">
<div class="author-time">
<span><?php echo $n['name'];?></span>
发表于 <span><?php echo date('Y-m-d h:i:s', $n['publish']);?></span>
</div>
<div class="news-des">
<h3 class="news-title" style="float: left;"><i></i><a href=javascript:;"><?php echo $n['title'];?></a></h3>
<div class="operate"><a href="javascript:;">编辑</a> <a href="javascript:;">删除</a></div>
<div style="clear:both"></div>
<div class="news-content-des ellipsis"><?php echo $n['content'];?></div>
</div>
</div>
<?php endforeach;?>
注意:封装的函数在这里