A simple PHP & amp; MYSQL message board source code page 1/2 _ PHP Tutorial

Source: Internet
Author: User
A simple PHP & amp; MYSQL message board source code page 12th. It took me a few nights to write a message board for PHP beginners. Please correct p.s. my space does not support PHP, and I cannot provide a demo of the T_T database structure: (database name: lyb) Table 1: admin field: id (int11 beginner PHP, spent a few nights writing a message board, please correct
P.s. my space does not support PHP and does not support T_T demonstration.
Database structure: (database name: lyb)
Table 1: admin
Field: id (int11) name (varchvr) password (varchvr)
Table 2: lo
Field: id (int11) username (varchvr) sex (varchvr) qq (varchvr) email (varchvr) info (text) ip (varchvr) submit_time (datetime)
1 conn. php (connect to the database file)

Mysql_connect ("localhost", "root", ""); // connect to the database
Mysql_select_db ("lyb"); // select a database
?>
2 header. php (public header file)

The code is as follows:






Silver message board Version 1.0







  • Even check the message

  • Even post

  • // Session_start (); // DOFY indicates that no output content exists before this sentence. correct this.
    If ($ _ SESSION ["key"] = 1) {// if the obtained SESSION is 1, the management item is displayed.
    ?>
  • Exit Management

  • }
    Else
    {
    ?>
  • Even Management




Silver message board Version 1.0




3 footer. php (public bottom file)

The 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 boring silver digit "." $ num "."

";
Exec ("rm-rf $ counterFile ");
Exec ("echo $ num> $ counterFile ");
}
If (! File_exists ($ counterFile )){
Exec ("echo 0> $ counterFile ");
}
DisplayCounter ($ counterFile );
?>



4 index. php (home page)

The code is as follows:


Require_once ("conn. php ");
Require_once ("header. php ");
Session_start ();

// Start with paging code
$ Pagesize = 10; // you can specify the number of entries displayed on each page.
$ Rs = mysql_query ("select count (*) from lo"); // retrieves the total number of records and calculates the total number of pages.
$ Myrow = mysql_fetch_array ($ rs );
$ Numrows = $ myrow [0]; // calculates the total number of records.

$ Pages = intval ($ numrows/$ pagesize );
If ($ numrows % $ pagesize) $ pages ++; // you can specify the number of pages.
If (isset ($ _ GET ['Page'])
{
$ Page = intval ($ _ GET ['Page']);
}
Else
{
$ Page = 1; // Set it to the first page
}
$ Offset = $ pagesize * ($ page-1); // calculates the record offset.
// The paging code ends.


$ SQL = "select id, username, sex, qq, email, info, ip, DATE_FORMAT (submit_time, '% Y % m % d % t ') from lo order by id desc limit $ offset, $ pagesize "; // The DATE-FORMAT is used.
$ 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") // change the gender to the name you want ^_^
{
$ Sex = "Shuai pan ";
}
Else
{
$ Sex = "beauty ";
}


?>


No [ ] Messages


Message recipient: Gender: 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 "homepage | ";
Echo "previous page | ";
Echo "next page | ";
Echo "last page | ";
}
Elseif ($ page >=1 & $ page! = $ Pages & $ num> 0)
{
Echo "homepage | ";
Echo "previous page | ";
Echo "next page | ";
Echo "last page | ";
}
Elseif ($ page ==$ pages & $ page! = 1)
{
Echo "homepage | ";
Echo "previous page | ";
Echo "next page | ";
Echo "last page | ";
}
Elseif ($ page = $ pages)
{
Echo "homepage | ";
Echo "previous page | ";
Echo "next page | ";
Echo "last page | ";
}
Else
{
Echo "homepage | ";
Echo "previous page | ";
Echo "next page | ";
Echo "last page | ";
}
?>
Total Page | current Page | total & Nbsp messages





Mysql_close ();
?>

Require_once ("footer. php ");
?>


P.s. my space does not support PHP. I cannot provide a demo of the T_T database structure: (database name: lyb) Table 1: admin field: id (int11...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.