Recursive | pagination | tree structure Now I will show you the results of the practice, the disadvantage is that the method of pagination is not very good, can not show the specific number of pages, but there is no other better solution, had to do so, if there is similar to this forum of the paging method, the table enlighten one or two, two springs are appreciated! Specific access to my personal small Web site: HTTP://WEB.NYIST.NET/~WBGWRQ, no nonsense, start ...
The structure of the table is as follows:
Creat.sql
Brief description: Rootid topic ordinal number; Layer: Post level, indentation basis; Orders: Order of posts
CREATE TABLE Over_post (
ID Int (one) not NULL auto_increment,
Title varchar not NULL default ',
Content text,
Postat datetime not NULL default ' 0000-00-00 00:00:00 ',
readed Int (one) not NULL default ' 0 ',
Size int (one) not NULL default ' 0 ',
Rootid Int (one) 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
$result =mysql_query ($query) or Die (Mysql_error ());
endif
if ($result) {
Include "list.php";
}
?>
Post.php End
Plays, showing all posts, and implementing pagination
list.php
Begin
<?php
Find the Rootid of the latest topic
$query = "Select Max (Rootid) as Maxid1, Min (rootid) as minid1 from Over_post";
$result = mysql_query ($query);
$maxid 1 = mysql_result ($result, 0, "maxid1");
$startid 1 = mysql_result ($result, 0, "minid1");
if (!) ( $maxid 1>0)) $maxid 1=0;
if (!) ( $startid 1>0)) $startid 1=0;
$totalid 1 = $maxid 1; This is really the largest rootid value, $maxid 1 to be changed according to $NEXTMAXID1
if ($nextmaxid 1>0) $maxid 1= $nextmaxid 1; Page
Calculate the minimum Rootid: note the following DESC, combined with limit, to ensure the selection of the range of records.
If you use ASC, retrieving the No. 0 in Mysql_result will be a big mistake!
$itemsperpage = 30;
$query = "SELECT distinct Rootid from Over_post where rootid<= $maxid 1 order BY Rootid DESC
$itemsperpage ";
$r =mysql_query ($query);
$n =mysql_num_rows ($R);
if ($n >0) {
$minid 1=mysql_result ($r, $n-1);
$query = "SELECT * from Over_post where rootid<= $maxid 1 and rootid>= $minid 1 order by Rootid
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.