Here my example is made using the MySQL database method, the code is as follows:
One: Release the news file pub.php and pub_ok.php, the code is as follows:
File pub.php:
<form name="form1" method="post" action="pub_ok.php" onsubmit="javascript:return Juge(this);" >
<table width="90%" border="0" cellspacing="1" cellpadding="1" align="center">
<tr> <td> 标题: </td></tr>
<tr> <td> <input type="text" name="title" size="80"> </td> </tr>
<tr> <td> 详细内容:</td></tr>
<tr> <td> <textarea name="detail" style="width=80%;height=160px;">>/textarea<
</td></tr>
<tr><td><input type="submit" name="pub" value="发布"></td></tr>
</table>
</form>
File pub.php:
<?php include "common_news.php";?>
<title> Press Releases </title>
<body bgcolor= #cccccc ><?php
if ($pub) {$title =htmlspecialchars ($title);
$detail =htmlspecialchars ($detail);
$detail = Str_replace ("
"," <br> ", $detail); $pub _time=date ("Y"). " -". Date (" M ")." -". Date (" D ")." ". Date (" H ").": ". Date (" I ").": ". Date (" S ");
$query = "INSERT INTO News (title,detail,pub_time) values";
$query. = "(' $title ', ' $detail ', ' $pub _time ')";
$result =mysql_query ($query, $db);
echo "<div align= ' center ' >";
if ($result) {
echo <p> Release Success! <a href= ' view.php?page=1 ' > View </a>, <a href= ' pub.php ' > Release </a></p> ';
}
else{
Echo Mysql_error ();
echo "<p> release failed! </p> ";
}
echo "</div>";
}
?>
</body>
$id =mysql_connect (' localhost ', ' root ', ' cgreen ');
$db =mysql_select_db (' db_news ', $id);
$page _size=5;
?>
Show news item File: view.php
<?php include "common_news.php";?><title> Press Releases </title>
<script language=javascript>
function View (URL)
{
Popup=window.open (URL, "Displaywindow", "left=30,top=30,width=600,height=400,toolbar=no,location=no,directories= No,status=no,menubar=no,scrollbars=yes, Resizable=no ");
}
</SCRIPT>
<center>
News list
</center>
<?php
if ($page) {$query = "SELECT count (*) as Total from news";
$result =mysql_query ($query, $db);
$message _count=mysql_result ($result, 0, "total");
$page _count=ceil ($message _count/$page _size);
$offset = ($page-1) * $page _size;
$query = "SELECT * from news ORDER BY id desc limit $offset, $page _size";
$result =mysql_query ($query, $db);
if ($result) {
$rows =mysql_num_rows ($result);
$i = 1;
?>
<?php
while ($myrow =mysql_fetch_array ($result)) {
?>
<table width= "422" border= "0" cellspacing= "1" cellpadding= "1" align= "Center" >
<tr>
<TD width= "277" ><li><a href= "Javascript:view (' view_d.php?recid=<?php echo $myrow [id]?> ');" ><?php echo "$myrow [title]</a> ($myrow [pub_time])";?></td>
</tr>
</table>
<?php
$i + +;
if ($i <= $rows) {
echo "";
}
}
?>
<?php
$prev _page= $page-1;
$next _page= $page +1;
?>
<center>
<?php
if ($page <=1) {
echo "First page";
}
else{
echo "<a href= ' $PATH _info?page=1 ' > First page </a>";
}
echo "";
if ($prev _page<1) {
echo "Prev";
}
else{
echo "<a href= ' $PATH _info?page= $prev _page ' > Prev </a> ';
}
echo "";
if ($next _page> $page _count) {
echo "Next page";
}
else{
echo "<a href= ' $PATH _info?page= $next _page ' > next page </a>";
}
echo "";
if ($page >= $page _count) {
echo "last Page";
}
else{
echo "<a href= ' $PATH _info?page= $page _count ' > last page </a> ';
}
}
else{
echo "<p align= ' center ' > now has no news!/p>";
}
}
?>
<p> </p>
</body>