guestbook.php:
<title></title>
Senior Class <6> Message Book
|
|
Include ("Connect.rec"); $QH =mysql_query ("Select COUNT (*) as rcnt from Guestbook"); $data =mysql_fetch_array ($QH); $NR = $data ["rcnt"]; Determines whether the offset parameter is passed to the script, and if not, uses the default value of 0 if (empty ($offset)) { $offset = 0; } Query results (Here are 20 per page, but you can completely change it yourself) $result =mysql_query ("SELECT * from Guestbook ORDER BY time Desc LIMIT $offset, 5"); $result =mysql_query ("SELECT * from Guestbook LIMIT $offset, 5"); Shows the 5 records returned while ($data =mysql_fetch_array ($result)) { printf ("Name:%s ", $data [" name "]); printf ("email:%s ", $data [" Mail "]); printf ("Personal page:%s ", $data [" url "]); printf ("From:%s ", $data [" IP "]); printf ("Message Time:%s ", $data [" Time "]); printf ("Subject:%s ", $data [" title "]); printf ("Content:%s ", $data [" ly "]); printf (" "); } Next, write a link to another page if ($offset)//If the offset is 0, the previous page link is not displayed { $preoffset = $offset-5; Print "previous page n"; } Calculate the total number of pages required $pages =ceil ($NR/5); $pages variable now contains the required number of pages for ($i =1; $i <= $pages; $i + +) { $newoffset =5* $i-5; print "$i n"; } Check if it is the last page $next = $offset +5; if ($next < $NR) { Print "next page n"; } printf ("Back") ?>
|
ly.php:
Include ("Connect.rec");
$name = $T 1;
$mail = $T 2;
$url = $T 3;
$title = $T 4;
$time = Date ("Y-m-j h:i:s");
$ip = getenv ("REMOTE_ADDR");
$ly = $S 1;
$result = mysql_query ("INSERT into Guestbook (name,mail,url,ip,time,title,ly) VALUES (' $name ', ' $mail ', ' $url ', ' $ip ', ' $ Time ', ' $title ', ' $ly ');
if ($result = = 1)
{
Echo ("Message success! ");
printf ("");
}
Else
{
Echo ("Message failed!") ");
printf ("return");
}
?>
The above describes the free message of this php+mysql write a simple message This example code, including the content of the free message, I hope that the PHP tutorial interested in a friend helpful.