I believe that every person who has ever been to Oso will have a deep impression on the Oso forum, which is a good one in that respect. Do you want your homepage to have such a beautiful forum, in fact, is not too complicated, below we only from a few basic parts to achieve the Oso forum imitation.
Since I only use this forum as my message board, so my forum can be regarded as the Oso forum of simple matching. 1, in my forum only after the user login to speak, the user ID is the existence of a "cookie_user" cookie variable, 2, my forum has no sub-forum, 3, I do not count a topic of clicks, 4, In the OSO forum in front of each topic to indicate there is no new posts of the icon I did not design, 5, for the Oso forum to provide the choice of subject arrangement and display time period I did not consider, 6, no member post points statistics, 7, no moderator management forum function, 8, no post editing functions. We will finally mention how to expand these eight functions on the basis of my program.
The first is a database design, in fact, a forum involving two data tables, we will be named as user, Guestbook, in the user table is stored in the user information is registered users. Its creation statement is as follows:
CREATE TABLE My_user (
user_id Char (a) not null,/* user name */
User_password varchar (8) Not null,/* user password */
PRIMARY KEY (user_id)
)
The contents of the posts are stored in the guestbook. The content is created as follows:
CREATE TABLE Guestbook (
ID bigint DEFAULT ' 0 ' not NULL auto_increment,/* spoke ID, self-increment field */
Name varchar (one) not null,/* theme Creator */
Type tinyint not null,/* types 0-reply; 1-Main paste */
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,/* last reply time */
Answer_count int not null,/* reply number */
Answer_name varchar () not null,/* last reply to Person */
main_id bigint null,/* main sticker id*/
PRIMARY KEY (ID)/**/
);
The program consists of 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-CONNECT to database");
@mysql_select_db ("$dbName") or Die ("Unable to select database");
?>
faq.php: (Used to display a list of topics)
<title>Difficult issues</title>
Only members can speak here
!--? 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 posts: |
!--? php $query = "SELECT count (*) FR Om Guestbook "; $res = mysql_query ($query); $row = mysql_fetch_row ($res); Echo $row [0]; ?> |
|
href= "post.php" > Border=0 src= "Mypic /post.gif "; |
Main Problem |
Color= #ffffff > Creator |
color= #ffffff > Reply |
color= #ffffff > Reply person |
color= #ffffff > Last reply time |
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 "
". $row [' theme ']; echo ""; if ($row [' Answer_count ']>5) {echo "echo" Class=small color= #666666 > pagination : "; for ($j =1; $j <= ($row [' Answer_count ']-1)/5+1; $j + +) echo ""; } echo " | "; echo "
"; echo $row [' name ']. " | "; $ii = $row [' Answer_count ']-1; echo "
". $ii." | "; echo "
"; echo $row [' Answer_name ']. " | "; echo "
". $row [' mydate ']." |
";}?>
page Out: $page 1= $page-1; $page 2= $page +1; if ($page ==1) echo "first front page"; else echo "first front page"; if ($page = = $totalpage) echo "Back Page last"; else echo "Back Page last"; ?>
|
http://www.bkjia.com/PHPjc/316720.html www.bkjia.com true http://www.bkjia.com/PHPjc/316720.html techarticle I believe that every person who has ever been to Oso will have a deep impression on the Oso forum, which is a good one in that respect. Do you want to your homepage also has such a drift ...