A forum for imitating Oso (i) _php Foundation

Source: Internet
Author: User
Tags php source code

I believe that everyone who has been to the Oso will be very impressed by the Oso forum, which is a very good forum on the one hand. Do you want your homepage to have such a beautiful forum, in fact, not too complicated, below we only from some basic part of the Oso forum to achieve the imitation.
Because I only use this forum as my message board, so my forum can be regarded as the Oso forum of the simple match. 1, in my forum only after the user login to speak, the user ID is there is a "cookie_user" cookie variable, 2, my forum does not have sub-forum, 3, I do not count the number of clicks on a theme, 4, In the OSO forum in front of each topic to indicate that there are no new posts icon I did not design, 5, for the Oso forum to provide the choice of topic arrangement and display time period I did not consider, 6, no member posts points statistics, 7, no moderator management forum function, 8, no post editing function. In the end, we'll mention how to expand these eight features on my program.
The first is a database design, in fact, a forum involving two data tables, we will temporarily name it user, guestbook, in the user table is stored in the user's information. Its creation statement is as follows:
CREATE TABLE My_user (
user_id Char (a) not null,/* username */
User_password varchar (8) Not null,/* user password */
PRIMARY KEY (user_id)
)
The contents of the posts are stored in the guestbook. It is created as follows:
CREATE TABLE Guestbook (
ID bigint DEFAULT ' 0 ' not NULL auto_increment,/* speaker ID, self-added field * *
Name varchar not null,/* Theme Creator */
Type tinyint not null,/* 0-reply; 1-Main Post * *
Theme varchar () null,/* Theme * *
Content blob not null,/* contents * *
Icon tinyint not null,/* emoticons * *
Time_open datetime not null,/* Theme creation time * *
Time_close datetime not null,/* final reply time * *
Answer_count int not null,/* reply number * *
Answer_name varchar (a) Not null,/* final reply person * *
main_id bigint null,/* Main paste id*/
PRIMARY KEY (ID)/**/
);
The program contains five PHP source code: connect.inc.php,faq.php,read.php,post.php,reply.php,post_end.php
connect.inc.php: (Used to connect to the database)
?
$dbhostname = "localhost";
$dbusername = "";
$dbpassword = "";
$dbName = "";
Mysql_connect ($dbhostname, $dbusername, $dbpassword) or DIE ("Unable to CONNECT to database");
@mysql_select_db ("$dbName") or Die ("Unable to select database");
?>


faq.php: (Used to display a list of topics)
<HTML><HEAD><TITLE> Difficult issues </TITLE>
<link href= "Mypic/style.css" Rel=stylesheet type=text/css><body bgcolor= #cccc99 bottommargin=0 leftmargin=0 topmargin=0 marginwidth= "0" marginheight= "0" >
<table border=0 cellpadding=0 cellspacing=0 width= "100%" >
<TBODY>
<script Language=javascript
Src= "Mypic/x.js" ></SCRIPT>
<TR>
&LT;TD valign=top> Only members can speak here <BR>
<table align=center border=0 cellpadding=4 cellspacing=1 width=100% class=body_br >
<TBODY>
&LT;TD width=45%></font> Theme Number: <font
Color= #0772b1 >
<?php
Include "connect.inc.php";
$query = "SELECT count (*) from Guestbook where type=1";
$res = mysql_query ($query);
$row = Mysql_fetch_row ($res);
$total = $row [0];
$totalpage =floor ($total/20) +1;
Echo $total;
?>
Number of </font></td><td width=19%> posts: </TD>
&LT;TD Width=1%><font color= #0772b1 >
<?php
$query = "SELECT count (*) from Guestbook";
$res = mysql_query ($query);
$row = Mysql_fetch_row ($res);
echo $row [0];
?>
&LT;/FONT&GT;&LT;/TD&GT;&LT;TD WIDTH=1%&GT;&LT;/TD&GT;&LT;TD Align=middle Width=23%><a
href= "post.php" >Border=0
Src= "Mypic/post.gif" ></A></TD></TR>
<TR>
&LT;TD align=middle bgcolor= #6f6f6f ><font color= #ffffff > Master
Title </FONT></TD>
&LT;TD align=middle bgcolor= #6f6f6f ><font
color= #ffffff > Founder </FONT></TD>
&LT;TD align=middle bgcolor= #6f6f6f ><font
color= #ffffff > Reply </FONT></TD>
&LT;TD align=middle bgcolor= #6f6f6f ><font
color= #ffffff > Reply Person </FONT></TD>
&LT;TD align=middle bgcolor= #6f6f6f ><font
color= #ffffff > Final reply time </FONT></TD></TR>
<?php
function Tdbackcolor () {
Static $ColorStr;
if ($ColorStr = = "#ededed") {
$COLORSTR = "#dedede";
} else {
$COLORSTR = "#ededed";
}
return ($COLORSTR);
}
if (! $page) $page = 1;
$ysylimit = ($page-1) *20;
$query = "Select Theme,answer_count,id,name,answer_name,date_format (time_close, '%y-%m-%d ') as MyDate from Guestbook where type=1 order by Time_close DESC limit ". $ysylimit.", 20 ";
$res = mysql_query ($query);
For ($i =0 $i <20; $i + +) {
$row = @mysql_fetch_array ($res);
if (! $row) break;
$ColorStr =tdbackcolor ();
echo "<tr><td bgcolor=". $ColorStr. "Class=mid><a class=title href= ' read.php?theme_id= '. $row [' id ']." &page=1 ' > ' $row [' theme '];
echo "</A>";
if ($row [' Answer_count ']>5)
{echo "<font";
echo "Class=small color= #666666 > <B> pagination </b>:";
For ($j =1 $j <= ($row [' Answer_count ']-1)/5+1; $j + +) echo ' <a href= ' read.php?theme_id= '. $row [' id ']. " &page= ". $j." ' [". $j."] [1]</a> ";
}
echo "</td>";
echo "<td align=middle bgcolor=". $ColorStr. " > ";
echo $row [' name ']. </TD> ";
$ii = $row [' Answer_count ']-1;
echo "<td align=middle bgcolor=". $ColorStr. "Class=mid>". $ii. " </TD> ";
echo "<td align=middle bgcolor=". $ColorStr. " > ";
echo $row [' Answer_name ']. </TD> ";
echo "<td align=middle bgcolor=". $ColorStr. " ><font color= #ff8800 > ". $row [' mydate ']." </FONT></TD></TR> ";}
?>
</TBODY></TABLE>
&LT;HR size=1 width=100%>
<B> paging </b>:
<?php
$page 1= $page-1;
$page 2= $page +1;
if ($page ==1) echo "<font color= #999999 > front page </FONT>";
else echo "<a href= ' faq.php?page=1 ' > Home </A> <a href= ' faq.php?page= '. $page 1." ' > front page </A> ";
if ($page = = $totalpage) echo "<font color= #999999 > Next Last </FONT>";
else echo "<a href= ' faq.php?page=". $page 2. "' > Back page </A> <a href= ' faq.php?page= '. $totalpage. "' > Last </A> ";
?>
<form action=faq.php method=post><font class=mid> Current page: <b><?php echo $page. " /". $totalpage?></b> go to <select name=page onchange=javascript:location.href=this.options[ This.selectedindex].value>
<option selected
<?php
$k = 1;
echo "value=faq.php?page=". $k. " > ". $k." </OPTION> ";
For ($k =2 $k <=totalpage; $k + +)
echo "<option value=faq.php?page=". $k. " > ". $k." </OPTION> ";
?>
</SELECT> page </FONT>
</FORM></TD></TR></TBODY></TABLE>

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.