第15章 網際網路與TCP/IP

來源:互聯網
上載者:User

以上是表結構

寫一個支援的類

<?
   class articletype extends comm {
   
   
   
    
    private $article_type_id;//類型id
    private $article_parent_id;//父類id
    private $article_type_name;//類型名稱
    private $article_type_path;//路徑名稱
    private $is_send_message;
    private $is_hidden;
    private $look_right;
    private $model_type_id;
   
   /*
   get...set 協議進行初始化
   
   */
   
   
    function set_article_type_id($article_type_id){ $this->article_type_id=$article_type_id;}
    function get_article_type_id(){ return $this->article_type_id;}
    function set_article_parent_id($article_parent_id){ $this->article_parent_id=$article_parent_id;}
    function get_article_parent_id(){ return $this->article_parent_id;}
    function set_article_type_name($article_type_name){ $this->article_type_name=$article_type_name;}
    function get_article_type_name(){ return $this->article_type_name;}
    function set_article_type_path($article_type_path){ $this->article_type_path=$article_type_path;}
    function get_article_type_path(){ return $this->article_type_path;}
    function set_is_send_message($is_send_message){ $this->is_send_message=$is_send_message;}
    function get_is_send_message(){ return $this->is_send_message;}
    function set_is_hidden($is_hidden){ $this->is_hidden=$is_hidden;}
    function get_is_hidden(){ return $this->is_hidden;}
    function set_look_right($look_right){ $this->look_right=$look_right;}
    function get_look_right(){ return $this->look_right;}
    function set_model_type_id($model_type_id){ $this->model_type_id=$model_type_id;}
    function get_model_type_id(){ return $this->model_type_id;}
       
   
   
   
   
   
   /*
   
   add_articletype;
   
   */
   
   
   /*
   
   列表文章類別
   
   
   */
    function list_articletype(){
     global $db;
     global $article_type;
     $re=$db->query("select * from article_type order by article_type_path");
    // echo "<select>";
     while($r=$db->fetch_array($re)){
      $str="";
      if(substr_count($r['article_type_path'],',')>2){
       $str="|";
       for($i=0;$i<(substr_count($r['article_type_path'],',')-2);$i++){
       $str.="---";
       }
     
     }
    // echo "<option value={$r['article_type_id']}>".$str.$r['article_type_name']."</option>";
     //echo "<br>";
     $str=$str.$r['article_type_name'];
     $article_type[]=array('article_type_id'=>$r['article_type_id'],'article_type_name'=>$str,'article_parent_id'=>$r['article_parent_id'],'article_type_path'=>$r['article_type_path']);
    }
     //echo "</select>";
    }
    
    
    /*
    
    
    刪除類別的函數
    
    */
    function chk_del_article_type(){
    global $db;
      $sql="select article_parent_id from article_type where article_parent_id=".$this->get_article_type_id();
      $re=$db->query($sql);
      $num=$db->num_rows($re);
      if($num>0){
       echo "<script>alert(/"還有分類,你必須刪除分類/")</script>";
       echo '<script>window.location="javascript:history.back(-1)"</script>';
       exit;
       }
       $sql1="delete from article_type where article_type_id=".$this->get_article_type_id();
       $rt=$db->query($sql1);
        if($rt){
        
        echo "<script>alert(/"你刪除成功了/")</script>";
        echo '<script>window.location="javascript:history.back(-1)"</script>';
        }
       }
       
    /*
    
    增加父類
    
    */
    function add_parent_type(){
     global $db;
     /*
     
     產生sql語句
     
     */
     $sql="insert into article_type(article_parent_id,article_type_name,is_send_message,is_hidden,look_right,model_type_id) values(".$this->get_article_parent_id().",'".$this->get_article_type_name()."',".$this->get_is_send_message().",".$this->get_is_hidden().",".$this->get_look_right().",".$this->get_model_type_id().")";
     echo $sql;
     $db->query($sql);
     $id=$db->insert_id();
     $sql="update article_type set article_type_path='".",".$id.",' where article_type_id=".$id;
     $re=$db->query($sql);
      if($re){
       
      
      
       parent::showmessage("成功操作");//調用comm類的方法
       parent::jump("right.php?action=manage_news_type");//
      }else{
          $sql="delete from article_type where article_type_id=".$id;
       $db->query($sql);
       echo "<script>alert(/"插入資料失敗/")</script>";
       echo "<script>location.href=/"right.php?action=manage_news_type/"</script>";
      
      }
    }
       
       
      
      
      
      
       /*
       
       
       
       增加新聞子類別
       
       */
       
       
        function add_child_type(){
         global $db;
         /*
         
         產生sql語句
         
         */
         $sql="insert into article_type(article_parent_id,article_type_name,is_send_message,is_hidden,look_right,model_type_id) values(".$this->get_article_parent_id().",'".$this->get_article_type_name()."',".$this->get_is_send_message().",".$this->get_is_hidden().",".$this->get_look_right().",".$this->get_model_type_id().")";
         echo $sql;
         $db->query($sql);
         $id=$db->insert_id();
         /*
         
         查詢出父類接點的path
         */
         $article_type_path=$db->search('article_type','article_type_path','article_type_id='.$this->get_article_type_id(),'2');
         $path=$article_type_path['article_type_path'].$id.",";
         $sql="update article_type set article_type_path='".$path."' where article_type_id=".$id;
         $re=$db->query($sql);
          if($re){
           
          
          
           parent::showmessage("成功操作");//調用comm類的方法
           parent::jump("right.php?action=manage_news_type");//
          }else{
           $sql="delete from article_type where article_type_id=".$id;
           $db->query($sql);
           echo "<script>alert(/"插入資料失敗/")</script>";
           echo "<script>location.href=/"right.php?action=manage_news_type/"</script>";
          
          }
    }
       
      
       
       
       
       
       
       

    }
   
    
   
    
    
    
    
    
    
    /*
    
    執行個體化對象
    
    
    */
   $articletype=new articletype;
  

?> 

 

 

 

調用類的操作

<?

case 'del_article_type':
     $articletype->set_article_type_id($array['article_type_id']);
     $articletype->chk_del_article_type();
     break;
     
     
     
     
     case 'add_parent_root':
     $tp->display('add_parent_root.htm');
     break;
     
     
     /*
     
     擷取表單資料放入數組,提供給類,進行入庫操作
     
     */
     
     
     case 'chk_add_type':
      $ar=array(
      'article_type_name'=>$_POST['article_type_name'],
      'is_send_message'=>$_POST['is_send_message'],
      'is_hidden'=>$_POST['is_hidden'],
      'look_right'=>$_POST['look_right'],
      'model_type_id'=>$_POST['model_type_id'],
      
      
      );
      
      /*
      
      給類傳值 set   get方法
      */
      
      $articletype->set_article_type_name($ar['article_type_name']);
      $articletype->set_article_parent_id(0);
      $articletype->set_is_send_message($ar['is_send_message']);
      $articletype->set_is_hidden($ar['is_hidden']);
      
      $articletype->set_look_right($ar['look_right']);
      $articletype->set_model_type_id($ar['model_type_id']);
      $articletype->add_parent_type();
    
     break;
     
     
     /*
     
     增加子分類
     
     */

if($action=='chk_add_child_type'){
  
  $ar=array(
      'article_type_name'=>$_POST['article_type_name'],
      'is_send_message'=>$_POST['is_send_message'],
      'is_hidden'=>$_POST['is_hidden'],
      'look_right'=>$_POST['look_right'],
      'model_type_id'=>$_POST['model_type_id'],
      'article_type_id'=>$_POST['article_type_id']
      
      );
      
      /*
      
      給類傳值 set   get方法
      */
      $articletype->set_article_type_id($ar['article_type_id']);
      $articletype->set_article_type_name($ar['article_type_name']);
      $articletype->set_article_parent_id($article_type_id);
      $articletype->set_is_send_message($ar['is_send_message']);
      $articletype->set_is_hidden($ar['is_hidden']);
      
      $articletype->set_look_right($ar['look_right']);
      $articletype->set_model_type_id($ar['model_type_id']);
      $articletype->add_child_type();
  }

?>

相關文章

聯繫我們

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