An example of a recursive implementation of the Forum outline in PHP (for simplicity, I've removed the pagination display section)

Source: Internet
Author: User
Tags key query
Recursion | pagination | show <?php
/* The table structure where posts are stored
CREATE TABLE Announce (
announce_id Int (one) not NULL auto_increment,
board_id smallint (6) Not NULL,
Title varchar not NULL,
Content Tinytext,
Add_time datetime DEFAULT ' 0000-00-00 00:00:00 ' not NULL,
Auth_name varchar is not NULL,
Auth_mail varchar (40),
Hit_count smallint (6) Not NULL,
Bytes Mediumint (9) Not NULL,
parent_id tinyint (4) not NULL,
AUTH_IP varchar () not NULL,
top_id Int (one) not NULL,
Return_count tinyint (4) not NULL,
Face Char (3) is not NULL,
PRIMARY KEY (announce_id),
KEY board_id (board_id),
KEY top_id (top_id)
);
*/

function Show_announce ($id, $self _id) {
Global $dbconnect;
Global $board _id;
$query = "SELECT * from announce where announce_id= ' $id '";
$result =mysql_query ($query, $dbconnect);
$myrow =mysql_fetch_array ($result);
Mysql_free_result ($result);
echo "<li>\n";
echo " ';
if ($self _id!= $id)
echo "<a href= ' show.php3?board_id= $board _id&announce_id= $myrow [announce_id]&top_id= $myrow [top_id] ' > ";
echo $myrow [title];
if ($self _id!= $id)
echo "</a>";
echo "-<strong>" ". $myrow [Auth_name]." "</strong>" $myrow [Add_time]. "<font color=darkblue>[id: $myrow][announce_id] Click: $myrow [Hit_count]] </font> ($myrow [bytes] bytes) <font color=red> ($myrow [return_count]) </font>\n ";
$query = "Select announce_id from announce where parent_id= ' $id ' ORDER by announce_id DESC";
$result =mysql_query ($query, $dbconnect);
echo "<ul>\n";
while ($myrow =mysql_fetch_array ($result)) {
Show_announce ($myrow [announce_id], $self _id);
}
echo "</ul>\n";
Mysql_free_result ($result);
echo "</li>";
}
?>

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Forum Content </title>
<link rel= "stylesheet" type= "Text/css" href= "Common.css" >

<body>
<?php
You need to connect to the database here
You can add pagination to your needs
$query = "Select announce_id from announce where top_id= ' 0 ' ORDER by announce_id DESC";
$result _top=mysql_query ($query, $dbconnect);
echo "<ul>\n";
while ($myrow _top=mysql_fetch_array ($result _top)) {
Show_announce ($myrow _top[announce_id],0);
}
echo "</ul>\n";
Mysql_free_result ($result _top);
?>
</body>


Contact Us

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.

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.