PHP仿博客園個(gè)人博客數(shù)據(jù)庫與界面設(shè)計(jì)(4)_PHP教程
推薦:PHP session_start()問題解疑(詳細(xì)介紹)本文,將這些問題,做一個(gè)簡單的匯總,以便大家查閱。 1. 錯(cuò)誤提示 Warning: Cannot send session cookie - headers already sent Warning: Cannot send session cache limiter - headers already sent 分析及解決辦法 這 一類問題,的原因是你在程序中使用PHP session
$pagination = new Pagination; 這個(gè)類是我們的分頁類,我們傳入一個(gè) 總的數(shù)量給它,然后它自己會(huì)算出總頁數(shù),每跳轉(zhuǎn)一個(gè)頁面,相當(dāng)于刷新了一次,所以大家的做法就是,在構(gòu)造器里 GET(獲�。﹗rl上的page 的值,讓我們知道是當(dāng)前那一頁了。同時(shí)我們重新生成了查詢的語句,后面加上一條限制的語句,類似 limit $start(起始的id), $offset(長度); 原理就是從這個(gè)id起,往后給我10 條記錄;我的設(shè)定就是 10 條,你也可以更靈活。
$cat = new Category;這個(gè)類后面會(huì)詳細(xì)說,也是非常重要的分類model。這里我們就是簡單獲取 這個(gè)類型下的所有分類,顯示在側(cè)邊欄,我已經(jīng)完成了。有圖有真相!

這樣 我們的 $results 數(shù)組中就儲存了我們頁面所需的所有數(shù)據(jù)。 好的,來看看我們的模版,是怎么輸出的。
復(fù)制代碼 代碼如下:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>
博客后臺管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="assert/css/blog.css" />
</head>
<body id="Posts">
<table id="BodyTable" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td id="Header" colspan="2"><div id="SiteNav"></div>
<div id="BlogTitle">
Arist's Blog
</div>
<div id="Site Title">
<b><blockquote>Hinging there, everything will be fine.</blockquote></b>
</div>
</td>
</tr>
<tr>
<td>
<div id="LeftNavHeader">操作</div>
</td>
<td class="NavHeaderRow">
<ul id="TopNav">
<li><a href="post.php?action=IsPost">隨筆</a></li>
<li><a href="article.php?action=IsArticle">文章</a></li>
<li><a href="diary.php?action=IsDiary">日記</a></li>
<li><a href="comment.php?action=IsComment">評論</a></li>
<li><a href="photo.php?action=IsPhoto">相片</a></li& gt;
</ul>
<div id="SubNav">
當(dāng)前位置: <?php if( isset( $results['path'] )) echo $results['path']; ?>
</div>
</td>
</tr>
<tr>
<td class="NavLeftCell">
<div class="left_nav">
<ul id="LinksActions">
<li><a href="article.php?action=newArticle">» 添加新文章</a></li>
</ul>
</div>
<div id="CategoriesHeader" class="LeftNavHeader">
分類
</div>
<div class="left_nav">
<ul id="LinksCategories">
<li><a href="category.php?action=ListCat&type=article">[編輯分類]</a></li>
<li><a href="article.php?action=IsArticle">[所有分類]</a></li>
<li><a href="article.php?action=unCategory">[未分類]</a></li>
<?php
if( isset( $results['categories'] ) && ! empty( $results['categories'] ) ){
foreach( $results['categories'] as $category ){
echo <<<EOB
<li><a href="article.php?action=diffentCategoryArticle&catID={$category['category_id']}">{$category['name']}({$category['count_child_number']})</a></li>
EOB;
}
}
?>
</ul>
</div>
</td>
<td id="Body">
<div id="Main">
<div id="Editor_Messages">
<!-- 顯示提示信息 -->
<?php
if( isset( $results['statusMessage'] )){echo $results['statusMessage'];}
if( isset( $results['errorMessage'] )){echo $results['errorMessage'];}
?>
</div>
<div id="Editor_Results">
<div id="Editor_Results_Header" class="CollapsibleHeader">
<span id="Editor_Results_headerTitle">文章(主要用于轉(zhuǎn)載,發(fā)布原創(chuàng)博文要通過“隨筆”)</span>
</div>
<div id="Editor_Results_Contents">
<?php
if( isset( $results['posts'] )){
echo <<<EOB
<table id="Listing" class="Listing" cellspacing="0" cellpadding="0" border="0" style='width:98%;'>
<tr style="text-align: center">
<th valign="bottom">
標(biāo)題
</th>
<th width="40" style="text-align: center">
發(fā)布<br />
狀態(tài)
</th>
<th valign="bottom" width="50" style="text-align: center">
評論
</th>
<th width="50" style="text-align: center">
頁面<br />
瀏覽
</th>
<th valign="bottom" width="40" style="text-align: center">
操作
</th>
<th valign="bottom" width="40" style="text-align: center">
操作
</th>
</tr>
EOB;
foreach( $results['posts'] as $post ){
$time = date("Y-m-d H:i:s", $post['create_time']);
if( $post['status'] == "1" ){
$post['status'] = "發(fā)布";
} else {
$post['status'] = "<b>未發(fā)布</b>";
}
echo <<<EOB
<tr id="entry_{$post['post_id']}" class="Alt">
<td style="text-align: left">{$post['title']} ({$time})</td>
<td style="text-align: center">{$post['status']}</td>
<td style="text-align: center">{$post['view_count']}</td>
<td style="text-align: center">{$post['comment_count']}</td>
<td style="text-align: center"><a href="article.php?action=editArticle&postID={$post['post_id']}">編 輯</a></td>
<td style="text-align: center"><a href="JavaScript:if(confirm('從數(shù)據(jù)庫中刪除這篇文檔?')==true) {window.location='article.php?action=delete&postID= {$post['post_id']}';}">刪除</a></td>
</tr>
EOB;
}
echo "</table>";
if( isset( $pagination) ){$pagination->createLinks( ) ;}
} else {
echo "當(dāng)前無內(nèi)容!";
}
?>
</div>
</div>
<span id="currentPostId" style="display:none;"></span>
</div>
</td>
</tr>
</table>
<div id="blog_top_nav_block">
<div id="site_nav">
</div>
<div id="login_area">
<span id="span_userinfo"><b><?php echo $_SESSION['username']; ?> </b> <a href="?action=logout">logout</a></span>
</div>
<div class="clear"></div>
</div>
<table id="Footer" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">
<div>
© <?php echo date("Y", time( ) ); ?> Arist
</div>
</td>
</tr>
</table>
</body>
</html>
以上只是顯示數(shù)據(jù),人人都會(huì)啊。
我們怎么操作這些數(shù)據(jù)呢?
操作,就像是一種控制能力。 學(xué)生時(shí)代踢足球,我對球場有一種很強(qiáng)的控制能力,大學(xué)足球比賽拿了1次冠軍,1次亞軍,1次季軍,大四沒去,中學(xué)更是無數(shù)榮譽(yù)。
我的位置是中衛(wèi),在足球場上,這個(gè)位置,你得有統(tǒng)觀全局的能力,也得有很強(qiáng)的個(gè)人能力,還有指揮能力;扯的遠(yuǎn)了,現(xiàn)在天天坐在電腦前,這些東西也早就沒了,
就剩下些經(jīng)驗(yàn)之談。不過其中滋味,你也須也體驗(yàn)過。
我這個(gè)博客有個(gè)缺點(diǎn),每次你對數(shù)據(jù)庫進(jìn)行一次讀寫操作,你得刷新��!我知道這對服務(wù)器的負(fù)載很大,但是我覺得如果一個(gè)新技術(shù)你沒有完全吃透,盲目運(yùn)用,只會(huì)適得其反。
所以暫時(shí)我還是犧牲服務(wù)器的響應(yīng)時(shí)間,內(nèi)存消耗,來獲得一種相對的穩(wěn)定!
所以我對全局還不是很了解,還有很多未知地領(lǐng)域沒有涉入,如深入ajax,深入php,c 。。。 不多說了。
好了,看看怎么對數(shù)據(jù)進(jìn)行CRUD 吧!
DELETE 刪除
先看這個(gè)指令 post.php?action=delete&postID=132
當(dāng)我們確認(rèn)要?jiǎng)h除時(shí),這里有個(gè)注意的地方,我們能先要對該文檔所屬的分類下的 count_child_number 這個(gè)字段進(jìn)行 一個(gè)減 1 的操作。
為什么? 因?yàn)槲乙查_始犯了個(gè)邏輯錯(cuò)誤,刪除后我才調(diào)用這個(gè)方法,還記得嘛!reduceChildNumber( ) 有趣地地方就是這里,讓我受益匪淺!也讓我調(diào)試了N久!
分享:淺析PHP的ASCII碼轉(zhuǎn)換類本篇文章是對PHP的ASCII碼轉(zhuǎn)換類進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下 復(fù)制代碼 代碼如下: class ascii { function decode($str) { preg_match_all( /(d{2,5})/, $str,$a); $a = $a[0]; foreach ($a as $dec) { if ($dec 128) { $utf .= chr($dec); } else if ($dec
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問控制的和運(yùn)算符優(yōu)先級介紹
- 關(guān)于PHP語言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國語言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
- 相關(guān)鏈接:
- 教程說明:
PHP教程-PHP仿博客園個(gè)人博客數(shù)據(jù)庫與界面設(shè)計(jì)(4)
。