Beginner PHP, spent a few nights to write a message board, please correct me
P.S. My space does not support PHP and cannot provide 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 (datetim E
1 conn.php (Connection database file)
<?php
mysql_connect ("localhost", "root", "");/Connection Database
mysql_select_db ("Lyb");//Select Database
?>
2 header.php (Common header file)
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Silver Message Board Version 1.0</title>
<link href= "Css.css" rel= "stylesheet" type= "Text/css"/>
<body>
<?php session_start ();?>
<div id= "Head" >
<div id= "head_l" >
<ul>
<li><a href= "index.php" > I want to see message </a></li>
<li><a href= "post.php" > I want to publish </a></li>
<?php
Session_Start ()//dofy students to point out that this sentence can not have any output, this correction
if ($_session["key"]==1) {//if the obtained session is 1 then the admin item is displayed
?>
<li><a href= "adminexit.php" > Exit management </a></li>
?
}
Else
{
?>
<li><a href= "admin.php" > I want to manage </a></li>
?? >
</ul>
</div>
<div id= "Head_r" > Silver message Board Version 1.0</div>
</div>
3 footer.php (Common bottom file)
Copy Code code as follows:
<?php
$counterFile = "Conter.xml";
function Displaycounter ($counterFile) {
$fp = fopen ($counterFile, "RW");
$num = Fgets ($fp, 5);
$num + 1;
Print "<div id=\" footer\ "> Silver Message Board Version 1.0 You are the first". " $num "." A bit of a dull silver </div> ";
EXEC ("Rm-rf $counterFile");
EXEC ("echo $num > $counterFile");
}
if (!file_exists ($counterFile)) {
EXEC ("Echo 0 > $counterFile");
}
Displaycounter ($counterFile);
?>
</body>
4 index.php (home)
Copy Code code as follows:
<?php
Require_once ("conn.php");
Require_once ("header.php");
Session_Start ();
Start the paging code
$pagesize = 10;//Sets the number of display bars per page
$rs = mysql_query ("SELECT count (*) from lo");//Get total number of records, calculate total pages with
$myrow = Mysql_fetch_array ($RS);
$numrows = $myrow [0];//calculation total record
$pages = Intval ($numrows/$pagesize);
if ($numrows% $pagesize) $pages ++;//set Number of pages
if (Isset ($_get[' page '))
{
$page = intval ($_get[' page '));
}
Else
{
$page = 1;//Set as first page
}
$offset = $pagesize * ($page-1);//Calculate record offset
Pagination Code End
$sql = "Select Id,username,sex,qq,email,info,ip,date_format (submit_time, '%y%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 the name you want ^_^
{
$sex = "Shuai pan";
}
Else
{
$sex = "Beauty";
}
?>
<div id= "Show" >
<p class= "num" > [<?= $row [0]] message <p>
<p class= "Unline" > Message person: <span class= "Blue" ><?= $row [1]?></span> Sex: <?= $sex?> Message time: = $row [7]?> if ($row [3]) {?> <a href= "yun_qi_img/qq.gif" alt= "<?= $row [3]?>"/></A><? if ($row [4]) {?> <a href= "mailto:<?= $row [4]?>" >;? }?><? if ($_session["key"]==1) {?> ip:<?= $row [6]?> <a href= "update.php?wuleying&id=<?= $row [0]?>" > Change </a> <a href= "delete.php?wuleying&id=<?= $row [0]?>" > Delete </a>< ></a></p>
<p class= "Blue" > Message content:</p>
<div id= "Show_info" ><?= nl2br (Htmlspecialchars ($row [5])?></div>
</div>
<?php
}
}
Else
{
echo "<div id=\" show\ "> No data ......</div>";
}
?>
<div id= "Show_page" >
<p>
<?php
$first = 1;
$prev = $page-1;
$next = $page +1;
$last = $pages;
if ($page ==1&& $pages >1)
{
echo "Home |";
echo "prev |";
echo "<a href=\" index.php?page= ". $next." \ > next Page </a> | ";
echo "<a href=\" index.php?page= ". $last." \ > Last </a> | ";
}
ElseIf ($page >=1&& $page!= $pages && $num >0)
{
echo "<a href=\" index.php?page= ". $first." \ > Home </a> | ";
echo "<a href=\" index.php?page= ". $prev." \ "> Prev </a> | ";
echo "<a href=\" index.php?page= ". $next." \ > next Page </a> | ";
echo "<a href=\" index.php?page= ". $last." \ > Last </a> | ";
}
ElseIf ($page = = $pages && $page!=1)
{
echo "<a href=\" index.php?page= ". $first." \ > Home </a> | ";
echo "<a href=\" index.php?page= ". $prev." \ "> Prev </a> | ";
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 <span><?= $pages?></span> page | Current page <span><?= $page?></span> | A total of <span><?= $numrows ></span>  message </p>
</div>
<?php
Mysql_close ();
?>
<?php
Require_once ("footer.php");
?>
Current 1/2 page
12 Next read the full text