2016.6.23 PHP实现新闻发布系统主体部分

1.新闻发布系统的列表:

<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />      //这里的网页编码必须要保留,不然会导致网页的乱码
<?php 
ini_set("error_reporting","E_ALL & ~E_NOTICE");
?>
<?php
mysql_connect("localhost", "*****", "******");
mysql_select_db("member");
mysql_query("set character set utf8");
mysql_query("set name utf8");
$result=mysql_query("SELECT count(*) as total from `gonggao`");    //这里的''符号不能丢,必须使用英文输入法
$info=mysql_fetch_array($result);
$total=$info[total];
if($total==0)
{
echo "本站暂无公告!";
}
else
{
?>
<table width="645" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#EEEEEE">
<td width="355" height="20"><div align="center">公告主题</div></td>
<td width="162"><div align="center">发布时间</div></td>
<td width="128"><div align="center">查看内容</div></td>
</tr>
<?php

$pagesize=20;
if ($total<=$pagesize) {
$pagesize=1;
}

if (($total%$pagesize)!=0) {
$pagecount=intval($total/$pagesize)+1;
}else{
$pagecount=$total/$pagesize;
}

if (($_GET[page])=="") {
$page=1;
}else{
$page=intval($_GET[page]);
}
mysql_connect("localhost", "root", "yu19940606");
mysql_select_db("member");
mysql_query("set character set utf8");
mysql_query("set name utf8");
$resul=mysql_query("SELECT * from `gonggao` order by gg_time desc limit ".($page-1)*$pagesize.", $pagesize");

while($inf=mysql_fetch_array($resul)) {                                 //之前一直不能读取数据库就是因为这里, limit   和".($page-1)*$pagesize.",之间要加空格

?>
<tr>
<td height="20"><div align="left"><?php echo $inf[gg_title];?></div></td>
<td height="20"><div align="center"><?php echo $inf[gg_time];?></div></td>
<td height="20"><div align="center"><a href="gonggao.php?id=<?php echo $inf[gg_id]; ?>"> 查 看</a></div></td>
</tr>
<?php
}
?>
<tr>
<td height="20" colspan="3">&nbsp;
<div align="right">本站共有公告&nbsp;
<?php
echo $total;
?>
&nbsp;条&nbsp;每页显示&nbsp;<?php echo $pagesize;?>&nbsp;条&nbsp;第&nbsp;<?php echo $page;?>&nbsp;页/共&nbsp;<?php echo $pagecount;?>&nbsp;页
<?php
if ($page>=2) {
?>
<a href="gonggaolist.php?page=1" title="首 页"><font face="webdings"> 9 </font></a> <a href="gonggaolist.php?id=<?php echo $id;?>&amp;page=<?php echo $page-1;?>" title="前 一 页"><font face="webdings"> 7 </font></a>
<?php
}
if ($pagecount<=4) {
for ($i=1; $i<=$pagecount ; $i++) {
?>
<a href="gonggaolist.php?page=<?php echo $i;?>"><?php echo $i;?></a>
<?php
}
}else{
for ($i=1; $i<=4 ; $i++) {
?>
<a href="gonggaolist.php?page=<?php echo $i;?>"><?php echo $i;?></a>
<?php }?>
<a href="gonggaolist.php?page=<?php echo $page-1;?>" title="后 一 页"><font face="webdings"> 8 </font></a> <a href="gonggaolist.php?id=<?php echo $id;?>&amp;page=<?php echo $pagecount;?>" title="尾页"><font face="webdings"> : </font></a>
<?php }?>
</div>
</td>
</tr>
</table>
<?php
}
?></td>
</tr>
</table>
</html>

2.新闻发布系统的具体内容:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
ini_set("error_reporting","E_ALL & ~E_NOTICE");
?>
<table width="788" height="197" border="0" align="center" cellpadding="0" cellspacing="1">
<?php
mysql_connect("localhost", "****", "****");
mysql_select_db("member");
mysql_query("set character set utf8");
mysql_query("set name utf8");
$id=$_GET[id];                               //这里的id不是数据库中的gg_id    
$result=mysql_query("SELECT * from `gonggao` where gg_id='".$id."'");

$info=mysql_fetch_array($result);
include("function.php");

?>
<tr>
<td width="26" height="25" bgcolor="#FFFFFF"><div align="center"></div></td>
<td width="347" bgcolor="#FFFFFF"><div align="center">公告主题:<?php echo $info[gg_title];?></div></td>
<td width="88" bgcolor="#FFFFFF"><div align="center">发布时间:</div></td>
<td width="213" bgcolor="#FFFFFF"><div align="left"><?php echo $info[gg_time];?></div></td>
</tr>
<tr>
<td height="125" bgcolor="#FFFFFF"><div align="center"></div></td>
<td height="125" colspan="3" bgcolor="#FFFFFF"><div align="left"><?php echo $info[gg_content];?></div></td>
</tr>
</table>

上一篇:java I/O流


下一篇:DRP PK 牛腩新闻发布系统