PHP+MySQL简易新闻发布系统

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

新闻列表显示(List.php)

显示详细的新闻内容(View.php)

添加新闻(news_add.html news_add.php)

//connect.php连接到数据库

$db_host='localhost';

$db_user='root';

$db_pass='';

$conn=mysql_connect($db_host,$db_user,$db_pass)or die(mysql_error()."failed to connect to database!"); //连接数据库;

$db=mysql_select_db('news1',$conn);

>

//List.php

include "connect.php";

$page=$_GET["page"]+0;

$page=$page<=0?1:$page;

$page_size=10;

$query="SELECT id from news";

$result=mysql_query($query,$conn);

$total_records=mysql_num_rows($result);

$total_page=ceil($total_records/$page_size);

$page=$page>$total_page?$total_page:$page;

$offset=($page-1)*$page_size;

$query="SELECT * from news ORDER by id desc Limit $offset,$page_size";//第一个参数指定第一个返回记录行的偏移量,第二个参数指定返回记录行的最大数目

$result=mysql_query($query,$conn);

while($row=mysql_fetch_array($result)){

echo "

";

echo "

";

echo "

";

echo "

";

echo "

";

echo "

";

echo "

";

echo "

";

}

echo "

";

echo "".$row["title"]."";

echo "

";

echo "[".$row["author"]."]";

echo "

";

echo "[".$row["date"]."]";

echo "

";

echo "修改信息";

echo "

";

$prev_page=$page-1;

$next_page=$page+1;

if ($page<=1){

echo "首页|";

}

else{

echo "首页|";

}

if($prev_page<1){

echo "上一页|";

}

else{

echo "上一页|";

}

if ($next_page>$total_page){

echo "下一页|";

}

else{

echo "a href=$_SERVER[PHP_SELF]?page=$next_page>下一页|";

}

if ($page>=$$total_page){

echo "最后一页

\n";

}

else{

echo "最后一页";

}

>

发布信息

//View.php

include "connect.php";

$id=$_GET["id"];

if($id){

$query="SELECT * from news WHERE id"."=".$id;

$result=mysql_query($query,$conn) or die(mysql_error());

$row=mysql_fetch_array($result);

>

<?php echo $_GET["title"]?>

echo "

";

$i=0;

while ($i<$rows=mysql_num_rows($result)){

echo "

";

echo "

";

echo "

";

echo "

";

echo "

";

echo "

";

echo "

";

echo "

";

echo "

";

$i++;

}

echo "

";

echo "".$row["title"]."";

echo "

";

echo "作者:".$row["author"]."发表时间".$row["time"];

echo "

";

echo "".$row["content"]."";

echo "

";

}

>

返回列表

相关文档
最新文档