Beginner PHP, spent a few nights to write a message board, please master correct.
P.S. My space does not support PHP and cannot provide a demo t_t
Database structure: (Library name: LYB)
Table One: admin
Field: ID (int11) name (VARCHVR) password (VARCHVR)
Table II: LO
Field: ID (int11) Username (VARCHVR) Sex (VARCHVR) QQ (VARCHVR) Email (VARCHVR) info (text) IP (VARCHVR) submit_time (datetime)
1 conn.php (Connection database file)
mysql_connect ("localhost", "root", "");//Connect to Database
mysql_select_db ("Lyb");//Select Database
?>
2 header.php (Common header file)
Copy CodeThe code is as follows:
<title>Silver Message Board Version 1.0</title>
- I want to see the message
- I want to publish
Session_Start ();//dofy students pointed out that this sentence can not have any output content, this correction
if ($_session["key"]==1) {//If the obtained SESSION is 1, the management item is displayed
?>
- Exit management
}
Else
{
?>
- I want to manage
Silver Message Board Version 1.0
3 footer.php (Common bottom file)
Copy CodeThe code is as follows:
$counterFile = "Conter.xml";
function Displaycounter ($counterFile) {
$fp = fopen ($counterFile, "RW");
$num = Fgets ($fp, 5);
$num + = 1;
Print "Silver Message Board Version 1.0 You are the first". " $num "." Bit of boring silver ";
EXEC ("Rm-rf $counterFile");
EXEC ("echo $num > $counterFile");
}
if (!file_exists ($counterFile)) {
EXEC ("Echo 0 > $counterFile");
}
Displaycounter ($counterFile);
?>
4 index.php (home)
Copy CodeThe code is as follows:
Require_once ("conn.php");
Require_once ("header.php");
Session_Start ();
Pagination Code Start
$pagesize = 10;//Sets the number of bars per page
$rs = mysql_query ("SELECT count (*) from lo");//Get the total number of records, calculate total pages
$myrow = Mysql_fetch_array ($RS);
$numrows = $myrow [0];//calculates the total record
$pages = Intval ($numrows/$pagesize);
if ($numrows% $pagesize) $pages ++;//set pages
if (Isset ($_get[' page '))
{
$page = intval ($_get[' page ');
}
Else
{
$page = 1;//set to first page
}
$offset = $pagesize * ($page-1);//Calculate record offset
End of page code
$sql = "Select Id,username,sex,qq,email,info,ip,date_format (submit_time, '%y year%m month%d Days%T ') from lo Order BY id DESC limit $ Offset, $pagesize ";//used Date-format format date format
$result = mysql_query ($sql);
$num = mysql_num_rows ($result);
if ($num >0) {
while ($row = Mysql_fetch_array ($result))
{
echo Print_r ($row);
if ($row [2]== "male")//This makes the gender change the name you want ^_^
{
$sex = "Handsome pot";
}
Else
{
$sex = "Beauty";
}
?>
Article [ ] article message
Message person: Sex: message time: &site=http://www.loai.cn&menu=yes ">"/> " >"/ > IP: > Change > Delete
Message content:
}
}
Else
{
echo "no data ...";
}
?>
$first = 1;
$prev = $page-1;
$next = $page +1;
$last = $pages;
if ($page ==1&& $pages >1)
{
echo "Home |";
echo "prev |";
echo "Next page |";
echo "last |";
}
ElseIf ($page >=1&& $page! = $pages && $num >0)
{
echo "Home |";
echo "prev |";
echo "Next page |";
echo "last |";
}
ElseIf ($page = = $pages && $page!=1)
{
echo "Home |";
echo "prev |";
echo "Next page |";
echo "last |";
}
ElseIf ($page = = $pages)
{
echo "Home |";
echo "prev |";
echo "Next page |";
echo "last |";
}
Else
{
echo "Home |";
echo "prev |";
echo "Next page |";
echo "last |";
}
?>
Total page | current page | Total message
Mysql_close ();
?>
Require_once ("footer.php");
?>
http://www.bkjia.com/PHPjc/318008.html www.bkjia.com true http://www.bkjia.com/PHPjc/318008.html techarticle beginner PHP, spent a few nights to write a message board, please master correct P.S. My space does not support PHP and cannot provide a demo of the T_T Database structure: (Library name: LYB) Table one: admin field: ID (int11 ...