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

PHP開(kāi)發(fā) 小型論壇教程之論壇詳情

從我們的首頁(yè)點(diǎn)擊進(jìn)去進(jìn)去一個(gè)論壇,可以看到這個(gè)論壇里面所有發(fā)布的帖子

5.jpg

7.jpg


本頁(yè)面主要是從我們的 “tiopic”表中調(diào)數(shù)據(jù),然后再做個(gè)分頁(yè),代碼如下

<?php
session_start();
header("Content-type:text/html;charset=utf-8");    //設(shè)置編碼
$page=isset($_GET['page']) ?$_GET['page'] :1 ;//接收頁(yè)碼
$page=!empty($page) ? $page :1;
$F=$_GET['F'];
// 創(chuàng)建連接
$conn = mysqli_connect("localhost", "root", "root", "mybbs");
mysqli_set_charset($conn,'utf8'); //設(shè)定字符集
$table_name="tiopic";//查取表名設(shè)置
$perpage=5;//每頁(yè)顯示的數(shù)據(jù)個(gè)數(shù)
//最大頁(yè)數(shù)和總記錄數(shù)
$total_sql="select count(*) from $table_name";
$total_result =mysqli_query($conn,$total_sql);
$total_row=mysqli_fetch_row($total_result);
$total = $total_row[0];//獲取最大頁(yè)碼數(shù)
$total_page = ceil($total/$perpage);//向上整數(shù)
//臨界點(diǎn)
$page=$page>$total_page ? $total_page:$page;//當(dāng)下一頁(yè)數(shù)大于最大頁(yè)數(shù)時(shí)的情況
//分頁(yè)設(shè)置初始化
$start=($page-1)*$perpage;
$sql="select * from tiopic order by id desc limit $start ,$perpage";
$que=mysqli_query($conn,$sql);
$sum=mysqli_num_rows($que);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>帖子</title>
    <style>
        .cen{
            border: none;
            width: 600px;
            margin: 0 auto;
            height: 40px;
            background-color: rgba(34, 35, 62, 0.08);
        }
        .left{
            width: 535px;
            float: left;
        }
        .right{
            width: 65px;
            height: 30px;
            background-color:#B10707 ;
            float: left;
            margin-top: 8px;
        }
        .title{
            background-color: #B10707;
            color: white;
        }
        .list{
            margin-left: 12px;
        }
    </style>
</head>
<body>
<div class="cen">
<div class="left">
  <?php
 $sql1="select forum_name from forums where id='$F'";
 $squ1=mysqli_query($conn,$sql1);
 $row=mysqli_fetch_array($squ1);
 $forum_name=$row['forum_name'];
 echo "當(dāng)前論壇為:<a href=\"index.php\">$gb_name</a>-->>$forum_name";
 ?>
</div>
<div class="right"><a style="color: white" href="addnew.php">發(fā)布新帖</a> </div>
</div>
<table width="600px" border="1" cellpadding="8" cellspacing="0" align="center">
    <tr class="title">
        <td colspan="3">帖子列表 <span class="list">[<a style="color: white" href="index.php">返回</a> ]</span></td>
    </tr>
    <tr>
        <td width="280px">主題列表</td>
        <td width="160px" >作者</td>
        <td width="160px">最后更新</td>
    </tr>
    <?php
    if($sum>0) {
 while($row=mysqli_fetch_array($que)) {
 ?>
 <tr>
        <td width="280px"><div><a href="thread.php?id=<?php echo $row['id']?>"</a><?php echo $row['title']?></div> </td>
        <td width="160px"><?php echo $row['author'] ?></td>
        <td width="160px"><?php echo $row['last_post_time']?></td>
    </tr>
            <tr>
                <td colspan="3">
                    <?php }
                   }
 else{
 echo "<tr><td colspan='5'>本版塊沒(méi)有帖子.....</td></tr>";
                    } ?>
 </td>
            </tr>
    <tr>
        <td colspan="5">
            <div id="baner" style="margin-top: 20px">
                <a href="<?php
                echo "$_SERVER[PHP_SELF]?page=1"
 ?>">首頁(yè)</a>
                &nbsp;&nbsp;<a href="<?php
                echo "$_SERVER[PHP_SELF]?page=".($page-1)
 ?>">上一頁(yè)</a>
                <!--        顯示123456等頁(yè)碼按鈕-->
 <?php
                for($i=1;$i<=$total_page;$i++){
 if($i==$page){//當(dāng)前頁(yè)為顯示頁(yè)時(shí)加背景顏色
 echo "<a  style='padding: 5px 5px;background: #000;color: #FFF' href='$_SERVER[PHP_SELF]?page=$i'>$i</a>";
                    }else{
 echo "<a  style='padding: 5px 5px' href='$_SERVER[PHP_SELF]?page=$i'>$i</a>";
                    }
                }
 ?>
 &nbsp;&nbsp;<a href="<?php
                echo "$_SERVER[PHP_SELF]?page=".($page+1)
 ?>">下一頁(yè)</a>
                &nbsp;&nbsp;<a href="<?php
                echo "$_SERVER[PHP_SELF]?page={$total_page}"
 ?>">末頁(yè)</a>
                &nbsp;&nbsp;<span>共<?php echo $total?>條</span>
            </div>
        </td>
    </tr>
</table>
</body>
</html>

為了頁(yè)面美觀,我們做了CSS樣式和布局

我們現(xiàn)在‘tiopic ’表中沒(méi)有數(shù)據(jù),所以會(huì)顯示‘本版塊沒(méi)有帖子.....’

我們做了發(fā)布新帖的鏈接,下面我們做添加帖子的頁(yè)面



繼續(xù)學(xué)習(xí)
||
<?php session_start(); header("Content-type:text/html;charset=utf-8"); //設(shè)置編碼 $page=isset($_GET['page']) ?$_GET['page'] :1 ;//接收頁(yè)碼 $page=!empty($page) ? $page :1; $F=$_GET['F']; // 創(chuàng)建連接 $conn = mysqli_connect("localhost", "root", "root", "mybbs"); mysqli_set_charset($conn,'utf8'); //設(shè)定字符集 $table_name="tiopic";//查取表名設(shè)置 $perpage=5;//每頁(yè)顯示的數(shù)據(jù)個(gè)數(shù) //最大頁(yè)數(shù)和總記錄數(shù) $total_sql="select count(*) from $table_name"; $total_result =mysqli_query($conn,$total_sql); $total_row=mysqli_fetch_row($total_result); $total = $total_row[0];//獲取最大頁(yè)碼數(shù) $total_page = ceil($total/$perpage);//向上整數(shù) //臨界點(diǎn) $page=$page>$total_page ? $total_page:$page;//當(dāng)下一頁(yè)數(shù)大于最大頁(yè)數(shù)時(shí)的情況 //分頁(yè)設(shè)置初始化 $start=($page-1)*$perpage; $sql="select * from tiopic order by id desc limit $start ,$perpage"; $que=mysqli_query($conn,$sql); $sum=mysqli_num_rows($que); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>帖子</title> <style> .cen{ border: none; width: 600px; margin: 0 auto; height: 40px; background-color: rgba(34, 35, 62, 0.08); } .left{ width: 535px; float: left; } .right{ width: 65px; height: 30px; background-color:#B10707 ; float: left; margin-top: 8px; } .title{ background-color: #B10707; color: white; } .list{ margin-left: 12px; } </style> </head> <body> <div class="cen"> <div class="left"> <?php $sql1="select forum_name from forums where id='$F'"; $squ1=mysqli_query($conn,$sql1); $row=mysqli_fetch_array($squ1); $forum_name=$row['forum_name']; echo "當(dāng)前論壇為:<a href=\"index.php\">$gb_name</a>-->>$forum_name"; ?> </div> <div class="right"><a style="color: white" href="addnew.php">發(fā)布新帖</a> </div> </div> <table width="600px" border="1" cellpadding="8" cellspacing="0" align="center"> <tr class="title"> <td colspan="3">帖子列表 <span class="list">[<a style="color: white" href="index.php">返回</a> ]</span></td> </tr> <tr> <td width="280px">主題列表</td> <td width="160px" >作者</td> <td width="160px">最后更新</td> </tr> <?php if($sum>0) { while($row=mysqli_fetch_array($que)) { ?> <tr> <td width="280px"><div><a href="thread.php?id=<?php echo $row['id']?>"</a><?php echo $row['title']?></div> </td> <td width="160px"><?php echo $row['author'] ?></td> <td width="160px"><?php echo $row['last_post_time']?></td> </tr> <tr> <td colspan="3"> <?php } } else{ echo "<tr><td colspan='5'>本版塊沒(méi)有帖子.....</td></tr>"; } ?> </td> </tr> <tr> <td colspan="5"> <div id="baner" style="margin-top: 20px"> <a href="<?php echo "$_SERVER[PHP_SELF]?page=1" ?>">首頁(yè)</a>   <a href="<?php echo "$_SERVER[PHP_SELF]?page=".($page-1) ?>">上一頁(yè)</a> <!-- 顯示123456等頁(yè)碼按鈕--> <?php for($i=1;$i<=$total_page;$i++){ if($i==$page){//當(dāng)前頁(yè)為顯示頁(yè)時(shí)加背景顏色 echo "<a style='padding: 5px 5px;background: #000;color: #FFF' href='$_SERVER[PHP_SELF]?page=$i'>$i</a>"; }else{ echo "<a style='padding: 5px 5px' href='$_SERVER[PHP_SELF]?page=$i'>$i</a>"; } } ?>   <a href="<?php echo "$_SERVER[PHP_SELF]?page=".($page+1) ?>">下一頁(yè)</a>   <a href="<?php echo "$_SERVER[PHP_SELF]?page={$total_page}" ?>">末頁(yè)</a>   <span>共<?php echo $total?>條</span> </div> </td> </tr> </table> </body> </html>
提交重置代碼