PHP開發 新聞發布系統之新聞...登入

PHP開發 新聞發布系統之新聞列表頁面

建立新聞清單頁 new_list.php 檔案

#我們發佈的所有新聞都會在本頁顯示





首先先將數據從資料庫中找出來,程式碼如下

##

<?php
header("content-type:text/html;charset=utf8");
$conn=mysqli_connect("localhost","root","root","News");
mysqli_set_charset($conn,'utf8'); //设定字符集
$sql="select * from new";
$que=mysqli_query($conn,$sql);
?>
數據查出來了,我們要讓我們的資料在HTML頁面顯示,需要用到HTML和PHP語言混編

#程式碼如下

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP中文网</title>
    <style>
        table{
            margin-top: 10px;
        }
    </style>
</head>
<body>
<a href="new.html">返回发布新闻</a>
<table border="1" cellspacing="0" width=360 >
    <tr>
        <th>编号</th>
        <th>文章标题</th>
        <th>文章内容</th>
        <th>编辑文章</th>
        <th>发布时间</th>
    </tr>
    <?php
    while($row=mysqli_fetch_array($que)){
    ?>
    <tr>
        <td><?php echo $row['id'];?></td>
        <td><?php echo $row['title']?></td>
        <td><?php echo $row['content']?></td>
        <td>
            <a href="new_ed.php?id=<?php echo $row['id']?>">修改</a>
            <a href="new_del.php?id=<?php echo $row['id']?>">删除</a>
        </td>
        <td><?php echo $row['cre_time']?></td>
        <?php }
        ?>
    </tr>
</table>
</body>
</html>


new_list.php 檔案完整程式碼如下

###
<?php
header("content-type:text/html;charset=utf8");
$conn=mysqli_connect("localhost","root","root","News");
mysqli_set_charset($conn,'utf8'); //设定字符集
$sql="select * from new";
$que=mysqli_query($conn,$sql);
?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP中文网</title>
    <style>
        table{
            margin-top: 10px;
        }
    </style>
</head>
<body>
<a href="new.html">返回发布新闻</a>
<table border="1" cellspacing="0" width=360 >
    <tr>
        <th>编号</th>
        <th>文章标题</th>
        <th>文章内容</th>
        <th>编辑文章</th>
        <th>发布时间</th>
    </tr>
    <?php
    while($row=mysqli_fetch_array($que)){
    ?>
    <tr>
        <td><?php echo $row['id'];?></td>
        <td><?php echo $row['title']?></td>
        <td><?php echo $row['content']?></td>
        <td>
            <a href="new_ed.php?id=<?php echo $row['id']?>">修改</a>
            <a href="new_del.php?id=<?php echo $row['id']?>">删除</a>
        </td>
        <td><?php echo $row['cre_time']?></td>
        <?php }
        ?>
    </tr>
</table>
</body>
</html>
###上面的程式碼就可以把我們發佈所有的新聞以表格的形式在HTML頁面上展示#### ############################下一節
<a href="new.html">返回发布新闻</a> <table cellspacing="0" border="1" width="360"> <tbody><tr> <th>编号</th> <th>文章标题</th> <th>文章内容</th> <th>编辑文章</th> <th>发布时间</th> </tr> <tr> <td>1</td> <td>你好吗</td> <td>现在的你过的好吗</td> <td> <a href="new_ed.php?id=1">修改</a> <a href="new_del.php?id=1">删除</a> </td> <td>2016-11-03 09:31:26</td> </tr> </tbody></table>
章節課件