A forum program that mimics Oso (one)
Last Update:2017-02-28
Source: Internet
Author: User
I often use the Oso forum, personal feeling is very good, so imitate the interface of Oso compiled a program, share with everyone.
Program consists of three parts, that is, display the theme information, display forum information, add forum information, theme and forum content using master-slave table relationship.
The table structure is as follows:
drop table Fr_t_forumtitle;
CREATE TABLE Fr_t_forumtitle (
ID Integer,
State varchar (1),
Readcount Integer,
Replycount Integer,
Title varchar (100),
Createman varchar (20),
Replyman varchar (20),
Replytime datetime);
drop table fr_t_forumcontent;
CREATE TABLE Fr_t_forumcontent (
ID Integer,
Replyman varchar (20),
Replytime datetime,
Replyemail varchar (100),
Replyhttp varchar (100),
Replyface smallint,
Content text);
drop table Fr_t_parameter;
CREATE TABLE Fr_t_parameter (
Code varchar (10),
Name varchar (40),
Content varchar (10));
Insert into Fr_t_parameter (code,name,content) VALUES (' Pageline ', ' number of pages ', ' 20 '); /* Adjust this parameter to modify the number of rows per page * *
Program 1:mainforum.php
<link rel= "STYLESHEET" type= "Text/css" href= "Fp_zhangcg.css" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<meta name= "Microsoft Theme" content= "None" >
<meta name= "Microsoft Border" content= "None" >
<title> Forum </title>
<body bgcolor= "#C0C0C0" background= "BackColor. GIF ">
?
Include ("C:mydbheader.inc");
?>
<table width= "100%" border= "0" >
<tr class= "Text" >
<TD width= "50%" > <div align= "left" > Current location: Home--Forum </div> </td>
<TD width= "20%" > <div align= "center" > </div> </td>
<TD width= "10%" > <div align= "Center" >
<a href= "addmember.php" target=_blank> member registration </A></div> </td>
<TD width= "10%" > <div align= "center" > Forum Search </div> </td>
<TD width= "10%" > <div align= "center" > </div> </td>
</table>
?
$DBH = mysql_connect (' localhost:3306 ', ' root ', ');
mysql_select_db (' Test ');
$res =mysql_query ("Select content from Fr_t_parameter where code = ' Pageline '", $DBH);
$row =mysql_fetch_array ($res);
Global $pageline;
$pageline = $row ["Content"];
if (empty ($pageline)) {
$res =mysql_query ("INSERT into Fr_t_parameter (code,name,content) VALUES (' Pageline ', ' pages ', ')", $DBH);
$row =mysql_fetch_array ($res);
$pageline = 20;
}
$res =mysql_query ("Select COUNT (*) as rcnt from Fr_t_forumtitle", $DBH);
$row =mysql_fetch_array ($res);
$rcount = $row ["rcnt"];
$res =mysql_query ("Select COUNT (*) as Rcnt_con from Fr_t_forumcontent", $DBH);
$row =mysql_fetch_array ($res);
$rcon _count = $row ["Rcnt_con"];
print ' <table width= "100%" border= "0" > ";
print ' <tr class= ' text ' > ';
print ' <td width= ' 15% ' > </td> ';
print ' <td width= ' 35% ' > <div align= ' left ' > ';
Print "Number of topics:". $rcount. " Number of posts: ". $rcon _count;
print ' <td width= ' 35% ' > <div align= ' right ' > ';
print ' <a href= "addforum.php?theme_id=0" target= "_top" ></a>;
print ' <td width= ' 15% ' > </td> ';
print ' </td></table> ';
$pages =ceil ($rcount/$pageline); $pages variable now contains the required number of pages
if (empty ($offset)) {
$offset = 1;
$curline = 0;
} else
$curline = ($offset-1) * $pageline;
To print a table header
print ' <table width= "100%" border= "0" > ";
print ' <tr class= "text" > <td width= "50%" > <div align= "center" >;
if ($offset <> 1) {//If the offset is 0, do not display the link to the previous page
$newoffset = $offset-1;
Print "<a href= ' $PHP _self?offset= $newoffset ' > Prev </a>";
} else {
Print "Previous page";
Print "";
}
Calculate the total number of pages required
$pages =ceil ($rcount/$pageline); $pages variable now contains the required number of pages
for ($i =1; $i <= $pages; $i + +) {
$temps = "<a href= '". $PHP _self. '? Offset= '. $i. "' > ". $i." </a> ";
Print $temps;
Print "";
}
Check if it's the last page
if ($pages!=0 && $offset!= $pages) {
$newoffset = $offset +1;
Print "<a href= ' $PHP _self?offset= $newoffset ' > next page </a>";
else print "next page";
print ' </div> </td> ';
print ' <td width= ' 50% ' > <div align= ' center ' > ';
Print "Current page:". $offset. "Altogether". $pages. " Page ";
print ' </div> </td> ';
print "</table>";
Working with detailed information
print ' <table width= "100%" border= "1" > ";
print ' <tr class= ' text ' > ';
print ' <td width= ' 6% > <div align= ' center ' >New</div> </td> ';
print ' <td width= "5%" > <div align= "Center" > Click </div> </td> ';
print ' <td width= "53%" > <div align= "center" > Theme </div> </td> ';
print ' <td width= ' 10% ' > <div align= ' center ' > founder </div> </td> ';
print ' <td width= ' 5% ' > <div align= ' center ' > Reply </div> </td> ';
print ' <td width= "11%" > <div align= "center" > Last Modified Time </div> </td> ';
print ' <td width= "10%" > <div align= "Center" > Reply person </div> </td> ';
print ' </tr> ';
$query = ' Select Id,state,readcount,title,createman,replycount,replytime,replyman
From Fr_t_forumtitle to Replytime desc LIMIT '. $curline. ', 20 ';
$res = mysql_query ($query, $DBH);
$li _rownum = mysql_num_rows ($res);
for ($i =1; $i <= $li _rownum; $i + +) {
$row = Mysql_fetch_row ($res);
while ($row = Mysql_fetch_array ($res)) {
print ' <tr class= ' text ' > ';
print ' <td width= ' 6% ' > '. $row ["state]." </td> ';
print ' <td width= ' 5% ' ><div align= ' center ' > '. $row ["Readcount"]. ' </td> ';
$tempstr = "<a href= ' readforum.php?readflag=". $row ["id"]. "' > ". $row [' title ']." </a> ";
print ' <td width= ' 53% ' > '. $tempstr. ' </td> ';
print ' <td width= ' 48% ' > '. $row [title]. ' </td> ';
print ' <td width= ' 9% ' > '. $row ["Createman"]. ' </td> ';
print ' <td width= ' 5% ' ><div align= ' center ' > '. $row ["Replycount"]. ' </td> ';
$temptime = substr ($row ["Replytime"],5,11);
print ' <td width= ' 11% ' > '. $temptime. ' </td> ';
print ' <td width= ' 10% ' > '. $row ["Replyman"]. ' </td> ';
print ' </tr> ';
}
print "</table>";
Print Footer
print ' <table width= "100%" border= "0" > ";
print ' <tr class= "text" > <td width= "50%" > <div align= "center" >;
if ($offset <> 1) {//If the offset is 0, do not display the link to the previous page
$newoffset = $offset-1;
Print "<a href= ' $PHP _self?offset= $newoffset ' > Prev </a>";
} else {
Print "Previous page";
Print "";
}
Calculate the total number of pages required
for ($i =1; $i <= $pages; $i + +) {
$temps = "<a href= '". $PHP _self. '? Offset= '. $i. "' > ". $i." </a> ";
Print $temps;
Print "";
}
Check if it's the last page
if ($pages!=0 && $offset!= $pages) {
$newoffset = $offset +1;
Print "<a href= ' $PHP _self?offset= $newoffset ' > next page </a>";
else print "next page";
print ' </div> </td> ';
print ' <td width= ' 50% ' > <div align= ' center ' > ';
Print "Current page:". $offset. "Altogether". $pages. " Page ";
print ' </div> </td> ';
print "</table>";
End of print footer
?>
?
Include ("C:mydbfooter.inc");
?>
</body>