非遞迴法實現論壇樹型結構及分頁!!(心血結晶啊,呵呵)_PHP

來源:互聯網
上載者:User
關鍵字 呵呵 心血 結構 論壇 實現 rootid
現將本人的實踐結果show給大家,不足之處就是分頁的方法不太好,不能顯示具體的頁數,可實在又沒有其它更好的解決辦法,只好先如此了,如果哪位有類似本論壇的分頁方法,表賜教一二,二泉不勝感激!具體可訪問我的個人小網站:http://web.nyist.net/~wbgwrq,不廢話了,開始吧......

//表的結構如下:
//creat.sql
//簡單說明:RootId 論題序數;Layer:文章層次,縮排的依據;Orders:文章的順序
CREATE TABLE over_post (
id int(11) NOT NULL auto_increment,
title varchar(80) NOT NULL default ',
content text,
postat datetime NOT NULL default '0000-00-00 00:00:00',
readed int(11) NOT NULL default '0',
size int(11) NOT NULL default '0',
rootid int(11) NOT NULL default '0',
orders int(4) NOT NULL default '0',
layer int(4) NOT NULL default '0',
PRIMARY KEY (id)
) TYPE=MyISAM;
//creat.sql End

//發表根帖,即RootId,Layer,Orders為0的文章
//said.php
//begin

//said.php End


//文章內容,且在本頁進行跟帖
//content.php
//Begin

$result=mysql_query("select

over_post.title,over_post.content,over_post.postat,over_post.readed,over_post.rootid,over_post.la

yer,over_post.orders from over_post where over_post.id=$id");
$readed=mysql_result($result,0,"readed");
$title=mysql_result($result,0,"title");
$content=mysql_result($result,0,"content");
$date=mysql_result($result,0,"postat");
$rootid=mysql_result($result,0,"rootid");
$orders=mysql_result($result,0,"orders");
$layer=mysql_result($result,0,"layer");
?>












發表人:
主 題: 《》

Readed:】
內 容:




論壇發表跟帖

















題目:



內容:












//content.php End

//更新資料庫
//post.php
//Begin

$content=nl2br(htmlspecialchars($content));
$title=htmlspecialchars($title); //決不允許在標題上使用html
$date=date("Y-m-d H:i:s");
$length=strlen($content);

if(isset($said)) //發表新文章
{
$query="insert into over_post

values(null,'$title','$content',$user_id,'$date',0,$length,$img,',',')";
$result=mysql_query($query) or die(mysql_error());
$r=mysql_query("select max(id) from over_post");
$rootid = mysql_result($r,0)+0;
mysql_query("update over_post set rootid=$rootid where ID=$rootid")or die(mysql_error());
}

if(isset($reply)): //發表跟帖

mysql_query("update over_post set orders=orders+1 where rootid=$rootid and orders>$orders")or

die(mysql_error());

$layer=$layer+1;
$orders=$orders+1;
$query="insert into over_post

values(null,'$title','$content',$user_id,'$date',0,$length,$img,$rootid,$orders,$layer)";

$result=mysql_query($query) or die(mysql_error());

endif;
if($result) {
include"list.php";
}
?>
//post.php End

//重頭戲,顯示所有文章,並實現分頁
//list.php
//Begin

//找到最新論題的rootid
$query = "select max(rootid) as maxid1, min(rootid) as minid1 from over_post";
$result = mysql_query($query);
$maxid1 = mysql_result($result, 0, "maxid1");
$startid1 = mysql_result($result, 0, "minid1");
if(!($maxid1>0)) $maxid1=0;
if(!($startid1>0)) $startid1=0;
$totalid1 = $maxid1; //這是真正的最大的rootid值, $maxid1要根據$nextmaxid1變的
if($nextmaxid1>0) $maxid1=$nextmaxid1; //翻頁

//計算最小rootid:注意下面的desc,與limit結合,保證選取記錄的範圍.
//如果使用asc, 在mysql_result中檢索第0個,將大大錯誤!
$itemsperpage=30;
$query="select distinct rootid from over_post where rootid<=$maxid1 order by rootid desc limit

$itemsperpage";
$r=mysql_query($query);
$n=mysql_num_rows($r);
if($n>0) {
$minid1=mysql_result($r,$n-1);
$query="select * from over_post where rootid<=$maxid1 and rootid>=$minid1 order by rootid

desc,orders";
$result=mysql_query($query);
$num=mysql_num_rows($result);

}
else {
$minid1=0;
$maxid1=0;
echo "

沒有更多的發言內容";
}

$query="select distinct rootid from over_post where rootid>$maxid1 order by rootid limit

$itemsperpage";
$r=mysql_query($query);
$n=mysql_num_rows($r);
if($n>0) $up=mysql_result($r,$n-1);
else $up=$totalid1;

$query="select distinct rootid from over_post where rootid<$minid1 order by rootid desc limit

$itemsperpage";
$r=mysql_query($query);
$n=mysql_num_rows($r);
if($n>0) $down=mysql_result($r,0);
else $down=$maxid1;
?>














href="javascript:window.location.reload()" class=a1>重新整理
首頁 " class=a1>

上頁
" class=a1>下頁
:$startid1-$totalid1 ";?>

echo"
    ";
    while ($array=mysql_fetch_array($result)){
    $id=$array["id"];
    $title=$array["title"];
    $content=$array["content"];
    $postat=$array["postat"];
    $readed=$array["readed"];
    $size=$array["size"];
    if($size==0) $size="無內容";
    else $size.=" Bytes";
    $rootid=$array["rootid"];
    $orders=$array["orders"];
    $layer=$array["layer"];

    $ul=""; //開始樹型結構
    $_ul="";
    for($j=0;$j<$layer;$j++){
    $ul=$ul."
      ";
      $_ul=$_ul."
    ";
    }
    echo $ul."
  • "."$title($size) 【

    ".作者."】 $postat <被讀:$readed>
    ".$_ul;
    flush();
    //樹型結構結束
    }
    ?>

href="javascript:window.location.reload()" class=a1>重新整理
首頁 " class=a1>

上頁
" class=a1>下頁
:$startid1-$totalid1 ";?>



//list.php End
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.