?
/* Store the table structure of the posts------------------------------------------------------
The code is as follows |
Copy Code |
CREATE TABLE Bbsrow ( bbsrow_id Int (6) NOT NULL auto_increment,//posting ID number Bbsrow_auth varchar NOT NULL,//Post author Bbsrow_parentid Int (6),//The Father Post ID number of the posting, if the initial sticker is blank Bbsrow_title varchar NOT NULL,//posts title Bbsrow_returncount Int (3),//Post number of replies, if no replies are empty Primary KEY (BBSROW_ID) |
);
-----------------------------------------------------------------------------*/
A recursive function that shows the son's post--------------------------------------------------
code is as follows |
copy code |
function Showchildren ($parent _id) { Global $connect _id; $query = "SELECT * from Bbsrow where bbsrow_parentid= '". $parent _id. "'"; $result _top=mysql_query ($query, $connect _id); echo "<ul>"; while ($myrow _child=mysql_fetch_row ($result _top)) { echo "<li>"; Echo $myrow _child[0]; Echo $myrow _child[1]; Echo $myrow _child[2]; Echo $myrow _child[3]; Echo $myrow _child[4]. " "; //If the number of replies is not empty, it means that there is a son posted, continue to show the son paste if ($myrow _child[4]!= ') { Showchildren ($myrow _child[0]); } } echo "</ul>"; } |
//----------------------------------------------------------------------
Connect the database and put all the starter stickers in the $mainrow array----------------------------
The code is as follows |
Copy Code |
$connect _id=mysql_connect ("localhost", "Test", "test") or Die ("Unable to connect to database"); mysql_select_db ("BBS") or Die ("Cannot select Database"); $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 + +; } Mysql_free_result ($result); //---------------------------------------------------------------------- Start building a paging display------------------------------------------------------ if ($currentpage!= "") { $page = $currentpage; } else{ $page = 0; } $pagesize =10;//The number of initial stickers per page! $start = $page * $pagesize; $end = $start + $pagesize; if ($end > $i) $end = $i; $totalpage = $i/$pagesize; $info = "Total". $i. "Records, points". Ceil ($totalpage). "Page, current is paragraph." ($page + 1). "/" . Ceil ($totalpage). The page "; Echo $info; if ($page >0) $pagestr = "<a href=bbsrow.php4?currentpage=". ($page-1). "> Prev </a>"; $pagestr = $pagestr. "[subsection]; for ($i =0; $i < $totalpage; $i + +) { if ($i!= $page) { $pagestr = $pagestr. "<a href=bbsrow.php4?currentpage=". $i. ">". ($i + 1). "</a>"; } else{ $pagestr = $pagestr. " " . ($i + 1). " "; } } $pagestr = $pagestr. "Page]"; if ($page < $totalpage-1) $pagestr = $pagestr. "<a href=bbsrow.php4?currentpage=". ($page + 1). " > next page </a><p> "; Echo $pagestr; |
//----------------------------------------------------------------------
start outlining----------------------------------------------------------
The code is as follows |
Copy Code |
echo "<ul>"; for ($i = $start; $i < $end; $i + +) { echo "<li>"; echo $mainrow [$i][0]; echo $mainrow [$i][1]; echo $mainrow [$i][2]; echo $mainrow [$i][3]; echo $mainrow [$i][4]. " "; If the reply to the number of stickers is not empty, it means that there is a son posted, continue to show son stickers if ($mainrow [$i][4]!= ') { Showchildren ($mainrow [$i][0]); } } echo "</ul>";
|
----------------------------------------------------------------------? >