新聞分類錄入、顯示系統_PHP教程

來源:互聯網
上載者:User
本系統可以錄入標題、內容、圖片、相關軟體,顯示時會根據是否有有圖片和相關軟體來判斷是否顯示該項內容,開啟頁面顯示的是最新的一片文章,點擊目錄會顯示之前的文章。
建立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
*********************************


新聞錄入






*********************************
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 "

";
echo "

錄入成功

";
?>
*********************************
end of insert.php
*********************************

*********************************
新聞顯示檔案:news.php
*********************************


顯示類型1



$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 "".$title."
";
}
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 "
";
print $rows[2];
echo "
$rows[5]";
if (strlen($rows[4])>0) echo "

";
echo str_replace("\r","
",str_replace(" "," ",$rows[3]));
if (strlen($rows[6])>0) echo "

>>點擊下載

";
?>


*********************************
end of news.php
*********************************


【本文著作權歸作者與奧索網共同擁有,如需轉載,請註明作者及出處】


http://www.bkjia.com/PHPjc/316418.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/316418.htmlTechArticle本系統可以錄入標題、內容、圖片、相關軟體,顯示時會根據是否有有圖片和相關軟體來判斷是否顯示該項內容,開啟頁面顯示的是最新的...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.