Introduction: this non-recursive method is used to implement the Forum tree structure and pagination !! (Painstaking efforts, huh, huh) The detailed page describes the knowledge, skills, experience, and some PHP Source Code related to PhP.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 327695 'rolling = 'no'>
Now I will show you my practical results. The disadvantage is that the paging method is not good, and the specific page number cannot be displayed. But there is no better solution, so I have to do this first, if anyone has a paging method similar to this forum, I am very grateful to you! Visit my personal small Website: http://web.nyist.net /~ Wbgwrq, no nonsense. Let's get started ......
// The table structure is as follows:
// Creat. SQL
// Simple Description: The topic sequence number of the rootid; layer: The post level and indentation basis; orders: the post order
Create Table over_post (
Id int (11) not null auto_increment,
Title varchar (80) not null default ',
Content text,
Postat datetime not null default '2017-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
// Post a root post, that is, a post with a value of 0 for "rootid", "layer", and "orders"
// Said. php
// Begin
<Form method = "Post" Action = "post. php">
<Table width = "81%" border = "0" cellspacing = "1" cellpadding = "0" align = "center">
<Tr bgcolor = "#66 CCCC">
& Lt; TD Height = "35" width = "23%" & gt;
<Div align = "right"> your thoughts:
</Div>
</TD>
& Lt; TD Height = "35" width = "77%" & gt;
<Input type = "text" name = "title" size = "50" class = "EQ">
</TD>
</Tr>
<Tr bgcolor = "#66 CCCC">
& Lt; TD Height = "39" width = "23%" & gt;
<Div align = "right"> your content:
</Div>
</TD>
& Lt; TD Height = "39" width = "77%" & gt;
<Textarea name = "content" Cols = "50" rows = "10" class = "EQ"> </textarea>
</TD>
</Tr>
<Tr bgcolor = "#66 CCCC">
<TD colspan = "2" Height = "24">
</TD>
</Tr>
<Tr bgcolor = "#66 CCCC">
<TD colspan = "2" Height = "28">
<Div align = "center">
<Input type = "Submit" name = "said" value = "first">
<Input type = "reset" name = "submit2" value = "start from scratch">
</Div>
</TD>
</Tr>
</Table>
</Form>
// Said. php end
// Post content and post it on this page
// Content. php
// Begin
<? PHP
$ 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 ");
?>
<Table width = "90%" cellspacing = "1" bgcolor = "red" align = "center">
<Tr bgcolor = "# ffffff">
<TD width = "12%"> Publisher: </TD>
</Tr>
<Tr bgcolor = "# ffffff">
<TD width = "12%"> subject: </TD>
<TD colspan = "5"> <? PHP echo $ title;?> <Font color = "666666"> <I> 【
Readed: <? Echo "$ readed";?>] <? Echo "$ date";?> </I> </font> </TD>
</Tr>
<Tr bgcolor = "# ffffff">
<TD width = "12%"> content: </TD>
<TD colspan = "5"> <? PHP echo $ content;?> </TD>
</Tr>
</Table>
<Br>
<Center>
Forum posts
<Form method = "Post" Action = "post. php">
<Table width = "78%" cellspacing = "0" align = "center" cellpadding = "0" border = "0">
<Tr bgcolor = "# ffffff">
& Lt; TD Height = "24" width = "12%" & gt;
<Div align = "right"> question: </div>
</TD>
& Lt; TD Height = "24" width = "88%" & gt;
<Input type = "text" name = "title" class = "EQ" size = "50">
</TD>
</Tr>
<Tr bgcolor = "# ffffff">
& Lt; TD Height = "63" width = "12%" & gt;
<Div align = "right"> content: </div>
</TD>
& Lt; TD Height = "63" width = "88%" & gt;
<Textarea name = "content" class = "EQ" Cols = "50" rows = "10"> </textarea>
</TD>
</Tr>
<Tr bgcolor = "# ffffff">
<TD Height = "57" colspan = "2">
</TD>
</Tr>
<Tr bgcolor = "# ffffff">
<TD Height = "20" colspan = "2">
<Div align = "center">
<Input type = "Submit" name = "reply" value = "" class = in>
<Input type = "reset" value = "Override" class = in name = "reset">
<Input type = "hidden" name = "rootid" value = "<? Echo $ rootid;?> ">
<Input type = "hidden" name = "orders" value = "<? Echo $ orders;?> ">
<Input type = "hidden" name = "layer" value = "<? Echo $ layer;?> ">
</Div>
</TD>
</Tr>
</Table>
// Content. php end
// Update the database
// Post. php
// Begin
<?
$ Content = nl2br (htmlspecialchars ($ content ));
$ Title = htmlspecialchars ($ title); // you cannot use HTML on the title.
$ Date = date ("Y-m-d h: I: s ");
$ Length = strlen ($ content );
If (isset ($ said) // post a new post
{
$ 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): // post a post
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
// Highlights all posts and displays them by PAGE
// List. php
// Begin
<? PHP
// Find the latest topic's 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; // This is the largest value of the room. $ maxid1 must be changed according to $ nextmaxid1.
If ($ nextmaxid1> 0) $ maxid1 = $ nextmaxid1; // flip the page
// Calculate the minimum rootid. Pay attention to the following DESC, Which is used with limit to ensure the range of selected records.
// If ASC is used, retrieving 0th in mysql_result will be a big error!
$ 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 "<p> <center> <font color = '# ff0000'> no more content </font> </center> ";
}
$ 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;
?>
<Div align = center>
<Br>
<Table width = "90%" border = "0" cellspacing = "1" cellpadding = "0" align = "center">
<Tr bgcolor = "2880ac">
<TD Height = "20" align = "center"> <font color = "# ffffff"> <
Href = "javascript: window. Location. Reload ()" class = A1> refresh </a>
<A href = "list. php" class = A1> homepage </a> <a href = "list. php? Nextmaxid1 = <? Echo $ up;?> "Class = A1>
Previous Page </a>
<A href = "list. php? Nextmaxid1 = <? Echo $ down;?> "Class = A1> next page </a> <? Echo "existing topics
: $ Startid1-$ totalid1 ";?>
</Font> </TD>
</Tr>
<Tr>
<TD Height = "40" bgcolor = "# e0f0f8" cellspacing = "1">
<? PHP
Echo "<ul> ";
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 = "NO content ";
Else $ size. = "bytes ";
$ Rootid = $ array ["rootid"];
$ Orders = $ array ["orders"];
$ Layer = $ array ["layer"];
$ Ul = ""; // start the Tree Structure
$ _ Ul = "";
For ($ J = 0; $ j <$ layer; $ J ++ ){
$ Ul = $ ul. "<ul> ";
$ _ Ul = $ _ ul. "</ul> ";
}
Echo $ ul. "<li>". "<a href = \" content. php? Id = $ ID \ "class = big> $ title </a> <font color = 006699> ($ size )【
". Author."] $ postat <read: $ readed> </font> <br> ". $ _ ul;
Flush ();
// Tree structure ends
}
?> <Br> </TD>
</Tr>
<Tr bgcolor = "2880ac">
<TD Height = "20" align = "center"> <font color = "# ffffff"> <
Href = "javascript: window. Location. Reload ()" class = A1> refresh </a>
<A href = "list. php" class = A1> homepage </a> <a href = "list. php? Nextmaxid1 = <? Echo $ up;?> "Class = A1>
Previous Page </a>
<A href = "list. php? Nextmaxid1 = <? Echo $ down;?> "Class = A1> next page </a> <? Echo "existing topics
: $ Startid1-$ totalid1 ";?>
</Font> </TD>
</Tr>
</Table>
</Div>
// List. php end
"The non-recursive method implements the Forum tree structure and pagination !! (Painstaking efforts, huh, huh) "more related articles
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/327695.html pageno: 12.