PHPは簡単なニュース発表システムの実例を実現する

6806 ワード

この例では,PHP実装の簡単なニュース配信システムについて述べる.皆さんの参考にしてください.具体的には以下の通りです.
私の白、ずっと会社でテンプレートとフレームワークでPHPを书いて、时には基本的なsql文さえ忘れていることを発见して、だからPHPの基础を复习して、固める空想があります.ページ分けと検索、ソート、まだ書いていません.後で更新を続けます.(コード修正:検索とページング機能の追加)
articlePublish.html:



 

Insert title here


 
ニュースシステムを発表する
タイトル:
内容:



articlePublishDo.php:



date_default_timezone_set('Asia/Shanghai');
$title=trim($_POST['title']);
$content=trim($_POST['content']);
$time=date("y-m-d H:i:s");
require_once 'init.php';
$sql="insert into article(title,content,create_time) values('$title','$content','$time')";
//echo $sql;
$re=mysql_query($sql);//sql の
if($re){
echo「パブリッシュ 」;
echo ' 。}Else{echo";echo' 'を します.
}
mysql_close();//データベースを じる

articleList.php:




Insert title here








回到电脑里






/**
*検索
*/
$keyword=$_GET['search'];
/*ページング*/
$sql="select count(*) from article where title like '%$keyword%' or content like '%$keyword%'";
$res=mysql_query($sql);
//$count= (int)mysql_num_rows($result);
$arr=mysql_fetch_assoc($res);
while(list($key,$val)=each($arr)){
$count = (int)$val;
}
//echo $count;
$pageSize=4;
$page=floor($count/$pageSize)+1;//合計ページ数$page
echo $page;
//echo $page;
if(isset($_GET['page']))
{
//$currentPage = $_GET['page'];
if($_GET['page'] <=1){
$currentPage = 1;
}elseif ($_GET['page'] ?>= $page){
$currentPage = $page-1;
}else{
$currentPage = $_GET['page'];
}
}else
{
$currentPage=1;
}
$start = ($currentPage-1)*$pageSize;
$sql="select id,title,content from article where title like '%$keyword%' or content like '%$keyword%' limit $start,$pageSize";
//echo $sql;
$re=mysql_query($sql);//sql文の実行
while($arr=mysql_fetch_assoc($re)){
?>







mysql_close();//データベースを閉じる
??>
番号記事タイトル文章内容記事の編集

しゅうせい
カットアウト


共にページ|がバーレコード
現在ページ|
トップページ
&search=|次页
Insert title hererequire_once 'init.php';$sql="select id,title,content from article where id = '$id'";//echo $sql;$re=mysql_query($sql);//sql文の実行$arr=mysql_fetch_assoc($re);//var_dump($arr);mysql_close();//闭锁数据贝斯吗?>记事配信系统:内容:<?php echo $arr['content']??><br><a href="articleList.php"rel="noreferer noopener nofollow">記事リストに戻る</a><br><a href="articlePublish.html"rel="noreferer noopener nofollow">パブリッシュ記事に戻る</a><br>articleUpdate.php: <pre><code> <!--?php header("content-type:text/html;charset=utf8"); $arr=$_POST; $id=(int)$arr['id']; require_once 'init.php'; $sql="update article set title = '$arr[title]',content = '$arr[content]' where id = '$id'"; //echo $sql; $re=mysql_query($sql);//sql文の実行 //echo $re; if($re){ echo「修正成功」; echo"<a href='articleList.php'?-->記事リストを返します。 }else{ echo「修正に失敗しました」; echo "<a href="articleList.php"rel="noreferrer noopener nofollow">記事リスト</a>を返します。 } mysql_close();//データベースを閉じる </code></pre> <br>articleDelete.php: <pre><code> <!--?php header("content-type:text/html;charset=utf8"); require_once 'init.php'; $id=(int)$_GET['id']; $sql="delete from article where id = '$id'"; //echo $sql; $re=mysql_query($sql); if($re){ echo「削除成功」; echo"<a href='articleList.php'?-->記事リストを返します。 }else{ echo「削除に失敗しました」; echo "<a href="articleList.php"rel="noreferrer noopener nofollow">記事リスト</a>を返します。 } </code></pre> <br>init.php: <pre><code> <!--?php//データベース接続 //五歩歩 //データベースへの投稿の追加 $conn=mysql_connect("localhost","root","");//データベースのリンク //echo $conn; $re=mysql_select_db("article");//データベースの選択 mysql_query("set names utf8");//インタラクティブ文字セットの設定 </pre?--> </code></pre><br>基礎知識のまとめ:<br>投稿システム<br>1.articlePublish.html投稿页被送到articlePublishDo.php页,实行向数据贝斯写的<br>2.articleList.php报道名单<br>3.把编辑弄清,修正文章提出aiticleEdit.phpフォームページ(エコー)<br>4.文章的修正按钮提出articleUpdate.希望在php<br>本稿中所述的php程序设计中有用。