A concise multi-level forum

Source: Internet
Author: User

In this forum, less than 200 lines of code are used, and the execution speed is quite fast. Run the example in: http://www.hnpts.ha.cn/forum
MYSQL database: yxforum
+ ------- + -------------- + ------ + ----- + --------- + ---------------- +
| Field | Type | Null | Key | Default | Extra |
+ ------- + -------------- + ------ + ----- + --------- + ---------------- +
| Id | int (11) | PRI | 0 | auto_increment |
| Dt | datetime | YES | NULL |
| Tp | varchar (255) | YES | NULL |
| Ct | text | YES | NULL |
| Fl | int (11) | YES | NULL |
| Ip | varchar (20) | YES | NULL |
| Un | varchar (50) | YES | NULL |
| Em | varchar (60) | YES | NULL |
| Num | int (11) | YES | NULL |
+ ------- + -------------- + ------ + ----- + --------- + ---------------- +

Index. php:

<Html>
<Head>
<Style type = "text/css">

<! --
. Unnamed1 {font-size: 9pt; font-family: ""}
. Unnamed1 A {COLOR: #000088; FONT-SIZE: 9pt; TEXT-DECORATION: none; TEXT-TRANSFORM: none; font-family: ""}
. Unnamed1 A: hover {COLOR: #880000; FONT-SIZE: 9pt; TEXT-DECORATION: underline overline; font-family: "_ GB2312 "}
. Unnamed2 {font-size: 12px; color: # 9933FF}

-->

</Style>
</Head>
<Body bgcolor = "# FFFFFF" text = "#000000" link = "#000066" vlink = "# 0000CC" alink = "#000099">
<? $ M = mysql_connect ("localhost", "XXX", "XXX ");
Mysql_select_db ("××××", $ m );
?>

<? If ($ fl = "") $ fl = 1;
$ Hf_fl = $ fl;
$ Q = "select * from yxforum where id =". $ fl;
$ Mr = mysql_query ($ q, $ m );
$ Ra = mysql_fetch_row ($ mr );
?>
<P align = center> <B> <? Print ($ ra [2]);?> </B> <br>
<? If ($ fl! = 1 ){
?>
<Small> <? Printf ("(<a href = mailto: % s> % s </a>)", $ ra [7], $ ra [6]);?>
</Small> </p>
<? $ Alltt = $ ra [2];
$ Lastid = $ ra [4];
Print ("<center> <table width = 90% border = 1> <tr> <td bgcolor = # dddddd class = unnamed1> ". $ ra [3]. "</tr> </table> </center> ");
Print ("<br> <small> subject: </small> ");
}

$ Q = "select * from yxforum where fl =". $ fl. "order by dt desc ";
If ($ p = "") $ p = 0;
$ Mr = mysql_query ($ q, $ m );
$ F = mysql_num_fields ($ mr );

$ Ra = mysql_fetch_row ($ mr );
$ I = 0; $ p1 = $ p * 15;/* skip the row corresponding to the specified page number */
While ($ I <$ p1)
{$ I ++;
$ Ra = mysql_fetch_row ($ mr );
If (! $ Ra) break ;}


?>
<Center>
<Table border = 0 width = 732 class = "unnamed1">
<Tr align = "center" valign = "top" bgcolor = "# FFFFCC">
<Td width = "186"> latest response time
<Td width = "88"> publisher
<Td width = "414"> topic
<Td width = "44"> Response count
</Tr>
<?
$ X [0] = "ffffcc"; $ x [1] = "DEEFFF"; $ I = 1;
While ($ ra)/* display the current topic */
{$ Ys_c = $ I % 2;
Print ("<tr height = 12 bgcolor = #". $ x [$ ys_c]. "> <td align = center>". $ ra [1]);
Print ("<td align = center> <a href = mailto :". $ ra [7]. "> ". $ ra [6]. "</a> ");
Print ("<td> ");
Printf ("<a href = index. php? Fl = % s> % s </a> ", $ ra [0], $ ra [2]);
Print ("<td align = center>". $ ra [8]);
Print ("</tr> ");
$ Ra = mysql_fetch_row ($ mr );
$ I ++;
If ($ I> 15) break;
}

?>
</Table> </center>
<Form action = index. php method = get name = F0 onsubmit = "document. F0.p. value --; return true;">
<Span class = unnamed1>
<?
$ Alllines = mysql_affected_rows ($ m );
$ Pages = $ alllines/15;
If ($ pages-intval ($ pages )! = 0) $ pages = intval ($ pages) + 1;
Else $ pages = intval ($ pages );
Print ("Total". $ pages. "Page". ($ p + 1). "Page ");

If ($ p> 0) {printf ("<a href = index. php? Fl = % s> homepage </a> ", $ hf_fl );
Printf ("<a href = index. php? Fl = % s & p = % d> previous page </a> ", $ hf_fl, $ P-1 );}
If ($ ra) {printf ("<a href = index. php? Fl = % s & p = % d> next page </a> ", $ hf_fl, $ p + 1 );
Printf ("<a href = index. php? Fl = % s & p = % d> last page </a> ", $ hf_fl, $ pages-1 );}
?> Specify the <input type = text size = 2 name = p> page
</Span>
<Span class = unnamed1>
<? If ($ hf_fl! = 1) {printf ("<br> <a href = index. php? Fl = % s> upper level </a> ", $ lastid );
Print ("<a href = index. php> highest level </a> <br> ");}
?>
</Form> <center>
<Table width = 80% bgcolor = # eeeeff> <tr> <td class = unnamed1>
<? Print ($ fl = 1 )? "Add a new post:": "response:");?>
<Form action = "addnew. php" method = post name = "F1">
Name:
<Input type = "text" name = "nm" size = "15">
<Br>
Email:
<Input type = "text" name = "em" size = "45">
<Br>
Title (required ):
<Input type = "text" name = "tt" size = "45" <? If ($ fl! = 1) print ("value = reply:". $ alltt);?> >
<Input type = hidden name = "fl" value = "<? Print ($ hf_fl);?> ">
<Input type = hidden name = "p" value = "<? Print ($ p);?> ">
<Br>
Body (required): <br>

<Textarea name = "zw" cols = "50" rows = "10"> </textarea>
<Input type = "submit" name = "Submit" value = "submit">
</Form>
</Tr> </table> </center>
<Hr>
<Center> self-use design tool for Forum program version 0.25: PHP + MYSQL <br>
<A href = mailto: fhl@cgi.hnpts.ha.cn> ancient qingjian production </a> <br> <a href = http://www.fhlfox.dhs.org> Xiaoyao feihu Multimedia Workshop </a> 2000 </center>
</Span>
</Body>
</Html>



Addnew. php:

<? $ M = mysql_connect ("localhost", "XXX", "XXX ");
Mysql_select_db ("×××××", $ m );
$ Zw = ereg_replace ("<", "<", $ zw );
$ Zw = ereg_replace (">", ">", $ zw );
$ Zw = ereg_replace ("n", "<br>", $ zw );
$ Zw = ereg_replace ("", "", $ zw );
$ Tt = ereg_replace ("<", "<", $ tt );
$ Tt = ereg_replace (">", ">", $ tt );
If ($ nm = "") $ nm = "";
If ($ em = "") {$ nm. = "<-- is a newbie without MAIL"; $ em = "No ";}
$ Err = strlen ($ tt) * strlen ($ zw );
If ($ err = 0)
$ Msg = "<font color = red> don't be lazy! It is not too late to enter the form and submit it again. </Font> ";
Else {$ q = "insert into yxforum (dt, tp, ct, fl, ip, un, em, num) values"
. "(Now (),"". $ tt. "","". $ zw. "",". $ fl. ","". $ REMOTE_ADDR. "","". $ nm. "","". $ em. "", 0 )";
Mysql_query ($ q, $ m );

$ Q = "select num, fl from yxforum where id =". $ fl;
$ Fl_a = $ fl;
Do {$ mr = mysql_query ($ q, $ m );
$ Ra = mysql_fetch_row ($ mr );
$ Num = $ ra [0] + 1;
$ Q = "update yxforum set dt = now (), num =". $ num. "where id =". $ fl;
$ Fl = $ ra [1];
Mysql_query ($ q, $ m );
$ Q = "select num, fl from yxforum where id =". $ fl;
} While ($ fl> 0 );


$ Msg = "<font color = green> your comments have been submitted successfully! </Font> ";
}
?>
<Html>
<Head>
<Script language = "Javascript">
Function go ()
{Document. location = "index. php? Fl = <? Print ($ fl_a);?> & P = <? Print ($ p)?> ";
}
</Script>
<Body onload = "setTimeout ('go () ', 3000);">
<? Print ($ msg);?> <Br>
The system will automatically return after 3 seconds. If you cannot return a message or are in a hurry, please press <a href = index. php? Fl = <? Print ($ fl_a);?> & P = <? Print ($ p)?> Here </a>
</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.