当前位置: 首页 > 图文教程 > 网络编程 > PHP > 新闻分类录入、显示系统

PHP
PHP 变量类型的强制转换
PHP 判断变量类型实现代码
PHP 数组教程 定义数组
php后台程序与Javascript的两种交互方式
php 文件上传系统手记
php 网页游戏开发入门教程一(webgame+design)
PHP 简单日历实现代码
dedecms 批量提取第一张图片最为缩略图的代码(文章+软件)
php 显示指定路径下的图片
php pack与unpack 摸板字符字符含义
ThinkPHP php 框架学习笔记
PHP 批量删除数据的方法分析
PHP 读取和修改大文件的某行内容的代码
php实现jQuery扩展函数
浅谈PHP 闭包特性在实际应用中的问题
PHP 文件上传源码分析(RFC1867)
php 攻击方法之谈php+mysql注射语句构造
PHP+MySQL 手工注入语句大全 推荐
php UTF8 文件的签名问题
php 远程包含文件漏洞分析

PHP 中的 新闻分类录入、显示系统


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 62 ::
收藏到网摘: n/a

本系统可以录入标题、内容、图片、相关软件,显示时会根据是否有有图片和相关软件来判断是否显示该项内容,打开页面显示的是最新的一片文章,点击目录会显示之前的文章。
建立channelimages和channelsoft目录,并把权限设为777。
*********************************
news表结构
*********************************
# Host: localhost Database : yourdb
# --------------------------------------------------------
#
# Table structure for table 'yourtable'
#
CREATE TABLE news(
id int(11) DEFAULT '0' NOT NULL auto_increment,
kind varchar(16),
title varchar(60),
content text,
pic varchar(30),
timer datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
soft varchar(30),
PRIMARY KEY (id),
KEY timer (timer)
);
*********************************
新闻录入文件:insert.htm
*********************************
<html>
<head>
<title>新闻录入</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF">
<form name="form1" enctype="multipart/form-data" action="insert.php" method="post" >
<table width="81%" border="0" cellspacing="2" cellpadding="0" align="center">
<tr>
<td width="11%" align="right" bgcolor="#CC0000"><font color="#FFFFFF">标题:</font></td>
<td bgcolor="#E7E7E7">
<input type="text" name="title" size="60">
</td>
</tr>
<tr>
<td align="right" bgcolor="#CC0000"><font color="#FFFFFF">类别:</font></td>
<td bgcolor="#E7E7E7">
<input type="radio" name="kind" value="类型1">
类型1
<input type="radio" name="kind" value="类型2">
类型2
<input type="radio" name="kind" value="类型3">
类型3
<input type="radio" name="kind" value="类型4">
类型4</td>
</tr>
<tr>
<td width="11%" align="right" bgcolor="#CC0000"><font color="#FFFFFF">内容:</font></td>
<td bgcolor="#E7E7E7">
<textarea name="content" cols="60" rows="10"></textarea>
</td>
</tr>
<tr>
<td width="11%" align="right" bgcolor="#CC0000"><font color="#FFFFFF">图片:</font></td>
<td bgcolor="#E7E7E7">
<input type="file" name="pic" size="60">
</td>
</tr>
<tr>
<td width="11%" align="right" bgcolor="#CC0000"><font color="#FFFFFF">软件:</font></td>
<td bgcolor="#E7E7E7">
<input type="file" name="soft" size="60">
</td>
</tr>
<tr>
<td width="11%" align="right" bgcolor="#CC0000"> </td>
<td bgcolor="#E7E7E7">
<div align="center">
<input type="submit" name="Submit" value="提 交">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
*********************************
end of insert.htm
*********************************
*********************************
insert.php
*********************************
<?
$day=date("md");
If($pic != "none"){
$picname=$day.$pic_name;
copy($pic,"channelimages/$picname");
unlink($pic);
}
If($soft!= "none"){
copy($soft,"channelsoft/$soft_name");
unlink($soft);
}
$dbh = mysql_connect('localhost','uesrname','passward');
mysql_select_db('yourtable');
$dat=date("Y-m-d h:i:s");
$query="insert into news(title,kind,content,pic,timer,soft) values('$title','$kind','$content','$picname',now(),'$soft_name')";
$res = mysql_query($query,$dbh);
$err = mysql_error();
if($err){echo $err;exit();}
echo "<p></p><p align=center>";
echo "<body><h2>录入成功</h2></body></p>";
?>
*********************************
end of insert.php
*********************************
*********************************
新闻显示文件:news.php
*********************************
<html>
<head>
<title>显示类型1</title>
<meta http-equiv="目录类型" content="文本/html; 字符集=gb2312">
</head>
<body bgcolor="#FFFFFF">
<?
$db=mysql_connect("localhost","username","passward");
mysql_select_db("yourtable",$db);
$result=mysql_query("select id,title from news where kind='类型1' order by timer desc");
for($a=0;$a<10;$a++)
{if(!($ahrow=mysql_fetch_row($result)))break;
$id=mysql_result($result,$a,"id");
$title=mysql_result($result,$a,"title");
echo "<a href=news.php?id=".$id.">".$title."</a><br>";
}
if (!isset($id)) $id=mysql_result($result1,0,"id");
$result=mysql_query("select * from news where id=$id order by timer desc");
$rows=mysql_fetch_row($result);
echo "<br><center><font color=ff0000>";
print $rows[2];
echo "</font><br>$rows[5]</center>";
if (strlen($rows[4])>0) echo "<p><img src=channelimages/$rows[4] align=right>";
echo str_replace("\r","<br>",str_replace(" "," ",$rows[3]));
if (strlen($rows[6])>0) echo "</p><p align=right><a href=channelsoft/$rows[6]>>>点击下载</a></p>";
?>
</body>
</html>
*********************************
end of news.php
*********************************

【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】