PHP經典項目案例-(1)部落格管理系統3

來源:互聯網
上載者:User
PHP經典項目案例-(一)部落格管理系統3

本篇給出首頁左側導覽列及右部公告區的實現。

六、左側導覽列:

1、日曆:

這裡單獨一個php檔案,在顯示日曆的那個地方直接引用該檔案即可:

cale.php

"一月",         "02"=>"二月",         "03"=>"三月",         "04"=>"四月",         "05"=>"五月",         "06"=>"六月",         "07"=>"七月",         "08"=>"八月",         "09"=>"九月",         "10"=>"十月",         "11"=>"十一月",         "12"=>"十二月"     );     function setyear($year){    //設定年份         $this->year=$year;     }     function getyear(){   //獲得年份         return $this->year;     }     function setmonth($month){    //設定月份         $this->month=$month;     }     function getmonth(){    //獲得月份        return $this->month;     }     function setday($day){   //設定日期         $this->day=$day;     }     function getday(){   //獲得日期         return $this->day;     }     function OUT(){   //輸出日曆         $this->_env(); //設定顯示的日期        $week=$this->getweek($this->year,$this->month,$this->day);     //獲得日期為星期幾        $fweek=$this->getweek($this->year,$this->month,1);     //獲得此月第一天為星期幾         echo " 
week);$Tmpa++){ //輸出星期的標題 echo " "; for($Tmpa=0;$Tmpa "; } for($tmpb=1;$tmpb<=date("t",mktime(0,0,0,$this->month,$this->day,$this->year));$tmpb++){ //輸出所有日期 if(strcmp($tmpb,$this->day)==0){ //獲得當前日期,並採用特色顏色做為標記 $flag=" bgcolor='#FF3366'"; }else{ $flag=' bgcolor=#FAFDE2'; } if($tmpb==1){ echo " "; for($tmpc=0;$tmpc<$fweek;$tmpc++){ echo " "; } } if(strcmp($this->getweek($this->year,$this->month,$tmpb),0)==0){ //如果是周日 echo " "; }else{ echo " "; } } echo "
".$this->week[$Tmpa]."
$tmpb$tmpb
"; } //獲得方法內指定的日期的星期數 function getweek($year,$month,$day){ $week=date("w",mktime(0,0,0,$month,$day,$year)); //獲得星期 return $week; //獲得星期 } function _env(){ if(isset($_POST["month"])){ $month=$_POST["month"]; }else{ $month=date("m"); //預設為本月 } if(isset($_POST["year"])){ $year=$_POST["year"]; }else{ $year=date("Y"); //預設為本年 } $this->setyear($year); $this->setmonth($month); $date=sprintf('%1d',date('d')); $this->setday($date); }} $D=new calendar; $D->OUT(); ?>

在index.php裡面直接引用該檔案

    

2、最新文章顯示:

        
  execute_dql($sql); $i=1; while($info=$res->fetch_assoc()){ ?> 
   
" target="_blank">
   
這裡我去查詢資料庫的時候使用了自己的工具類sqlHelper.class.php

這裡給出上面用到的方法實現代碼:

sqlHelper.class.php部分代碼:

 class SqlHelper{                public $mysqli;        public $dbname="db_tmlog";        public $username="root";        public $password="root";        public $host="localhost";                public function __construct(){            $this->mysqli = new mysqli($this->host, $this->username, $this->password, $this->dbname);            if($this->mysqli->connect_error){                die("串連失敗".$this->mysqli->connect_error);            }            $this->mysqli->query("set names utf8");        }        //執行dql語句        public function execute_dql($sql){                        $res = $this->mysqli->query($sql) or die($this->mysqli->error);            //這裡返回的是一個結果集,當調用$row = $res->fetch_assoc()時是一條一條的向下走,應該使用while迴圈            return $res;        }                                                                                                                           }

dql語句就是簡單的查詢語句。

在使用資料庫查詢之前,先把這個檔案包進去,然後new一個工具類對象,然後使用對象調用裡面的函數。


3、最新圖片顯示


$sql="select id,tpmc,file from tb_tpsc order by id desc limit 2";$res2 = $sqlHelper->execute_dql($sql);while($info=$res2->fetch_assoc()){$query="select * from tb_tpsc where id=".$info['id']; $result=$sqlHelper->execute_dql($query); if($row = $result->fetch_assoc()){ $data = $row['file']; }?>
  " target="_blank"> " width="120" height="80" border="0">  
圖片名稱:
   

同樣使用了資料庫查詢。

4、公告區實現

在公告區使用了我以前沒有見過的一個標籤

它裡面設定了一些屬性,就是當滑鼠停留在上面的時候它就停止滾動,離開的時候就開始滾動。


$p_sql = "select * from tb_public order by id desc";        $p_rst = $sqlHelper->execute_dql($p_sql);?>while($p_row = $p_rst->fetch_row()){?>','','height=200,width=1000,scollbars=no')">
這個標籤是HTML5新增的,還有center標籤。那麼在使用的時候就會出現下面畫黃色波浪線的情況,我沒有去管他。

在這個超連結標籤裡,它設定了onclick這個屬性,onclick這個屬性後面跟的一定是js檔案裡面的函數,這個是開啟一個自訂寬高的視窗。href="#"表示這個超連結不串連到其他頁面,這裡超連結的響應使用onclick來設定了。


到這裡我們的首頁基本就實現了。這是index.php 的完整代碼:index.php提取碼:iu09


  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.