亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP開發(fā) 小型論壇教程之論壇版塊

我們從做論壇的第一步開始吧

第一步,從首頁(yè)開始:讀取數(shù)據(jù)庫(kù)中的信息。首頁(yè)主要是循環(huán)顯示‘forums’表中的所有論壇版塊。對(duì)于有基礎(chǔ)的人來(lái)說(shuō),查詢語(yǔ)句很容易:

<?php
header("Content-type:text/html;charset=utf-8");    //設(shè)置編碼
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "mybbs";
// 創(chuàng)建連接
$conn = mysqli_connect($servername, $username, $password, $dbname);
mysqli_set_charset($conn,'utf8'); //設(shè)定字符集
$sql="select * from forums";
$que=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($que)){
    echo "論壇 :".$row['forum_name'];
}
?>

這樣運(yùn)行,頁(yè)面沒有任何輸出,因?yàn)槲覀儎偨⒌臄?shù)據(jù)庫(kù)中沒有任何數(shù)據(jù)!那么,我希望讓論壇更加人性化,假如沒有論壇版塊應(yīng)該輸出“對(duì)不起,論壇尚在建設(shè)中??”的字樣應(yīng)該怎么辦??我們可以用mysql_num_rows()可以得到結(jié)果數(shù)目,代碼如下

<?php
header("Content-type:text/html;charset=utf-8");    //設(shè)置編碼
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "mybbs";
// 創(chuàng)建連接
$conn = mysqli_connect($servername, $username, $password, $dbname);
mysqli_set_charset($conn,'utf8'); //設(shè)定字符集
$sql="select * from forums";
$que=mysqli_query($conn,$sql);
$sum=mysqli_num_rows($que);
if($sum){
    while($row=mysqli_fetch_array($que)){
        echo "論壇 :".$row['forum_name'];
    }
}else{
    echo "對(duì)不起,論壇正在建設(shè)中,感謝你的關(guān)注......";
}
?>

我們現(xiàn)在來(lái)用css的樣式和布局來(lái)讓我們的頁(yè)面看起開更美觀一點(diǎn),代碼如下

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>論壇</title>
    <style>
        table{
            width: 55%;
            margin-top: 10px;
        }
        .title{
            background-color: #B10707;
            font-size: 17px;
            color: white;
        }
        .right{
            margin-left: 120px;
        }
    </style>
</head>
<body>
<table border="1px" cellspacing="0" cellpadding="8"align="center">
    <tr class="title">
        <td COLSPAN="3">
            論壇列表<span class="right">[<a style="color: white" href="add_forum.php">添加</a> ]</span>
        </td>
    </tr>
    <tr>
        <td width="10%"><strong>主題</strong></td>
        <td width="40"><strong>論壇</strong></td>
        <td width="15"><strong>最后更新</strong></td>
    </tr>
    <?php
 $sql="select * from forums";
 $que=mysqli_query($conn,$sql);
 $sum=mysqli_num_rows($que);
 if($sum>0) {
 while ($row = mysqli_fetch_array($que)) {
 ?>
 <tr>
                <td><?php echo $row['subject'] ?></td>
                <td><?php echo "<div class=\"bold\"><a class=\"forum\" href=\"forums.php?F=" . $row['id'] . "\">" . $row["forum_name"] . "</a></div>"
 . $row["forum_description"] ?></td>
                <td>
                    <div><?php echo $row["last_post_time"]?></div>
                </td>
            </tr>
            <?php
 }
    }else{
 echo "<tr><td colspan='3'>對(duì)不起,論壇正在建設(shè)中,感謝你的關(guān)注......</td></tr>";
    }
 ?>
</table>
</body>
</html>

現(xiàn)在數(shù)據(jù)庫(kù)中還沒有數(shù)據(jù),所以,我們運(yùn)行首頁(yè),只顯示“對(duì)不起,論壇尚在建設(shè)中??”。既然我們很希望看到結(jié)果,那么我們下一步就往數(shù)據(jù)庫(kù)中加幾條數(shù)據(jù)吧!




Weiter lernen
||
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>論壇</title> <style> table{ width: 55%; margin-top: 10px; } .title{ background-color: #B10707; font-size: 17px; color: white; } .right{ margin-left: 120px; } </style> </head> <body> <table border="1px" cellspacing="0" cellpadding="8"align="center"> <tr class="title"> <td COLSPAN="3"> 論壇列表<span class="right">[<a style="color: white" href="add_forum.php">添加</a> ]</span> </td> </tr> <tr> <td width="10%"><strong>主題</strong></td> <td width="40"><strong>論壇</strong></td> <td width="15"><strong>最后更新</strong></td> </tr> <?php $sql="select * from forums"; $que=mysqli_query($conn,$sql); $sum=mysqli_num_rows($que); if($sum>0) { while ($row = mysqli_fetch_array($que)) { ?> <tr> <td><?php echo $row['subject'] ?></td> <td><?php echo "<div class=\"bold\"><a class=\"forum\" href=\"forums.php?F=" . $row['id'] . "\">" . $row["forum_name"] . "</a></div>" . $row["forum_description"] ?></td> <td> <div><?php echo $row["last_post_time"]?></div> </td> </tr> <?php } }else{ echo "<tr><td colspan='3'>對(duì)不起,論壇正在建設(shè)中,感謝你的關(guān)注......</td></tr>"; } ?> </table> </body> </html>
einreichenCode zurücksetzen