文件名称:PHP实例之新闻发布系统源码下载
文件大小:5KB
文件格式:TXT
更新时间:2013-01-23 14:05:01
PHP实例之新闻发布系统
PHP实例之新闻发布系统 Create TABLE `news` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `p_time` DATETIME NOT NULL , `title` VARCHAR( 80 ) NOT NULL , `detail` TEXT NOT NULL ) TYPE = innodb; create table news(id int not null auto_increment primary key, p_time datetime not null, title varchar(80)not null, detail text not null )type=innodb; 数据库连接:conn.php <? $conn = @mysql_connect('localhost','root','')or die(mysql_error()."不能连接到数据库!"); //连接数据库; $db = mysql_select_db('news',$conn); $page_size = 8; //每页最多显示新闻条数; ?> 添加新闻页面:new.php <? $title="新闻发布系统"; include("inc/header.inc");//头文件 ?> <style type="text/css"> <!-- .STYLE1 {font-size: 12px} .title { font-size: 12px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; font-family: "宋体"; color: #993300; line-height: normal; height: 16px; } .field { font-family: "宋体"; font-size: 12px; color: #993333; } .STYLE2 { font-size: 16px; font-weight: bold; } --> </style>
PHP+Mysql新闻发布
<form action="post.php" method="post" name="frm" id="frm">标题: |
<input name="title" type="text" class="title" id="title" size="60" maxlength="80"></td> |
内容: |
<textarea name="textfield" cols="58" rows="6" class="field"></textarea> |
<input name="submit" type="submit" value="发布"></td> |
"; echo "新闻列表 继续发布"; } else { echo mysql_error()."
"; echo "发布失败!请返回"; } ?> 新闻列表:list.php <? include "conn.php"; $query = "Select COUNT(*) FROM news"; $result = mysql_query($query); $num = mysql_num_rows($result); $page_count = ceil($num/$page_size); //$offset = ($page_count-1)*$page_size; if(empty($_GET['page'])) { $page = 1; }else { $page = $_GET['page']; if($page<=0) { $page = 1; }else { $page >= $page_count; $page = $page_count-1; } } $query ="Select * FROM `news` orDER BY `id` DESC LIMIT ".($page-1)*$page_count.","."$page_size"; $result = mysql_query($query); ?>
标题 |
时间 |
|
<?php echo $l_result['id'];?>
|