Home  >  Article  >  Backend Development  >  Forum imitating OSO (1)_PHP tutorial

Forum imitating OSO (1)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:02:05930browse


I believe that everyone who has been to OSO will be deeply impressed by OSO’s forum. This forum is excellent in every aspect. Do you want to have such a beautiful forum on your homepage? In fact, it is not too complicated. Below we will only imitate the OSO forum from some basic parts.
Since I only use this forum as my message board, my forum can be regarded as a simple match of the OSO forum. 1. In my forum, users can only speak after logging in. The user's ID is stored in a cookie variable called "cookie_user". 2. My forum does not have sub-forums. 3. I do not count the number of clicks on a topic. , 4. I have not designed the icon in front of each topic in the OSO forum to indicate whether there are new posts. 5. I have not considered the optional topic arrangement and display time period provided by the OSO forum. 6. There is no statistics on members’ posting points. 7. There is no function for moderators to manage the forum. 8. There is no function for editing posts. We will touch on how to extend these eight functions based on my program at the end.
First is the design of a database. In fact, a forum involves two data tables. Let’s temporarily name them user and guestbook. The user table stores the information of registered users. The creation statement is as follows:
create table my_user(
user_id char(12) not null,/*username*/
user_password varchar(8) not null,/*user password*/
PRIMARY KEY (user_id)
)
The guestbook stores the post content.The creation content is as follows:
CREATE TABLE guestbook (
id bigint DEFAULT '0' NOT NULL auto_increment,/*speak id, auto-increment field*/
name varchar(12) NOT NULL,/*topic creation Person*/
type tinyint NOT NULL,/*type 0-reply; 1-main post*/
theme varchar(50) NULL,/*theme*/
content blob NOT NULL,/*content */
icon tinyint NOT NULL,/*emoticon*/
time_open datetime not NULL,/*topic creation time*/
time_close datetime not NULL,/*last reply time*/
answer_count int not null,/*number of replies*/
answer_name varchar(12) not null,/*last replyer*/
main_id bigint null,/*main post id*/
PRIMARY KEY (id) /**/
);
The program contains five php source codes: 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 "); " ;


                                                                  
src="mypic/x.js">

Only members can speak here

;TABLE align=center border=0 cellPadding=4 cellSpacing=1 width=100% class=body_br >
                                                                                                       $res = mysql_query($query);
$row = mysql_fetch_row($res);
$total =$row[0];
                                                                                1;
         echo $total; /TD>
                                              td width=1%>
                                                                           $res = mysql_query($query);  
                     $row = mysql_fetch_row($res);  
                     echo $row[0];
                     ?>
            
            href="post.php">            border=0  
          src="mypic/post.gif">
      
          主  
            题

                      color=#ffffff>创建人
                      color=#ffffff>回复
                      color=#ffffff>回复人
                      color=#ffffff>最后回复时间
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>  分页:";
    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']."";}
?>

      



分页
$page1=$page-1;
$page2=$page+1;
if ($page==1) echo "首页 前页 ";  
else echo "
首页 前页 ";  
if ($page==$totalpage) echo "后页 尾页 ";  
else echo "后页 尾页 ";  
?>
当前页:  转到第 页  
            



www.bkjia.comtruehttp://www.bkjia.com/PHPjc/316720.htmlTechArticle相信每一个到过OSO的人都会对OSO的论坛留下极深的印象,这个论坛无论从那一方面来说都是比较出色的。你想不想你的主页也有这么一个漂...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn