用 PHP+MYSQL 實現論壇裡的分級+分頁顯示_PHP教程

來源:互聯網
上載者:User
/*存放貼子的表結構------------------------------------------------------
create table bbsrow(
bbsrow_id int(6) not null auto_increment, //貼子ID號
bbsrow_auth varchar(20) not null, //貼子作者
bbsrow_parentid int(6), //貼子的父親貼子ID號,如為首發貼則為空白
bbsrow_title varchar(200) not null, //貼子標題
bbsrow_returncount int(3), //貼子的回複貼數,如果沒有回貼則為空白
primary key (bbsrow_id)
);
-----------------------------------------------------------------------------*/
//顯示兒子貼的遞迴函式--------------------------------------------------
function showchildren($parent_id){
global $connect_id;
$query="select * from bbsrow where bbsrow_parentid='" . $parent_id . "'";
$result_top=mysql_query($query,$connect_id);
echo "
n";
while($myrow_child=mysql_fetch_row($result_top)){
echo "
";
echo $myrow_child[0];
echo $myrow_child[1];
echo $myrow_child[2];
echo $myrow_child[3];
echo $myrow_child[4] . "n";
//如果回複貼數不為空白,則表示有兒子貼,繼續顯示兒子貼
if($myrow_child[4]!=''){
showchildren($myrow_child[0]);
}
}
echo "
";
}
//----------------------------------------------------------------------
//串連資料庫並將所有首發貼放到$mainrow數組裡----------------------------
$connect_id=mysql_connect("localhost","test","test") or die("無法串連資料庫");
mysql_select_db("bbs") or die("無法選擇資料庫");
$query="select * from bbsrow where bbsrow_parentid=''";
$result=mysql_query($query,$connect_id);
$i=0;
while($myrow=mysql_fetch_row($result)) {
$mainrow[$i][0]=$myrow[0];
$mainrow[$i][1]=$myrow[1];
$mainrow[$i][2]=$myrow[2];
$mainrow[$i][3]=$myrow[3];
$mainrow[$i][4]=$myrow[4];
$i++;
}

http://www.bkjia.com/PHPjc/631061.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631061.htmlTechArticle/*存放貼子的表結構------------------------------------------------------ create table bbsrow( bbsrow_id int(6) not null auto_increment, //貼子ID號 bbsrow_auth varchar(20)...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.