PHPsu
MANUAL ZH  |  EN
     


Current Position :| index>PHP CLASS> tableManage.class.php

tableManage.class.php

FROM: AUTHOR: TIME:2008-05-03 HITS:
class tableManage{
    var $field="title,content,addtime";
//    var $value="'\$ddd','\$www'";
    var $tablename="article";
function insert(){
     $value=$this->arrysplit($this->field,"'\$","'");
     $b="if (\$action==\"add\"){\r\n";
     $b.="    \$sql=\"Insert into ".$this->tablename."(".$this->field.",addtime) values(".$value.",now())\";\r\n";
     $b.="    mysql_query(\$sql) or die(\"无法插入数据,请检查输入数据是否完整\");\r\n";
     $b.="    echo \"数据添加成功\";\r\n";
     $b.="}\r\n";   
    return  $b; welcome to phpsu.com
    }
       
function delete(){
     $d="if (\$action==\"delete\"){\r\n";   
     $d.="    for(\$i=0;\$i<count(\$idarr);\$i++)
            {   
                 \$id = \$idarr[\$i];\r\n";
     $d.="        \$sql=\"delete from ".$this->tablename." where id=\$id\";\r\n";
     $d.="        mysql_query(\$sql) or die(\"无法删除数据\");\r\n";
     $d.="    }\r\n";
     $d.="        echo \"数据删除成功\";\r\n}\r\n";     
phpsu.com

    return  $d;
    }


function update(){
     $value=$this->arrysplit($this->field,"","|");
     $u="if (\$action==\"update\"){\r\n";
     $u.="    \$sql=\"update ".$this->tablename." set ".$value." where id=\$id\";\r\n";
     $u.="    mysql_query(\$sql) or die(\"无法更新数据\");\r\n";
     $u.="        echo \"数据更新成功\";\r\n";     
     $u.="}\r\n";
    return $u;
    }

function select(){
     $s="if (\$action==\"preupdate\"){\r\n";
     $s.="        \$sql=\"select * from ".$this->tablename." where id=\$id\";\r\n"; phpsu
     $s.="      \$result=mysql_query(\$sql) or die(\"查询数据出错\");\r\n";
     $s.="      if(\$arr=mysql_fetch_array(\$result));\r\n        {\r\n";   
     $str=$this->field;
     $str=explode(",",$str);
    for ($i=0;$i<count($str);$i++){
              $s .="          \$".$str[$i]."=\$arr[\"".$str[$i]."\"];\r\n";
    }
            $s .="          \$addtime=\$arr[\"addtime\"];\r\n";
     $s.="        }\r\n}\r\n";      phpsu
    return  $s;
    }
   
   
function move($classid=""){
     if ($classid=="") return "";
      $m="if (\$action==\"move\"){\r\n";   
     $m.="    for(\$i=0;\$i<count(\$idarr);\$i++)
            {   
                 \$id = \$idarr[\$i];\r\n";
     $m.="        \$sql=\"update ".$this->tablename." set $classid='\$$classid' where id='\$id'\";\r\n";
     $m.="      \$result=mysql_query(\$sql) or die(\"无法移动数据\");\r\n";
     $m.="    }\r\n";

www.phpsu.com


     $m.="        echo \"数据移动成功\";\r\n}\r\n";     
    return  $m;

}   
   
function  arrysplit($str,$stype="",$type=""){
    if(empty($str)) return "";
    $str=explode(",",$str);
    $strm="";
    for ($i=0;$i<count($str);$i++){
    $typer="='\$".$str[$i]."'";
         if ($type=="|")  $strm .=$stype.$str[$i].$typer;
         else     $strm .=$stype.$str[$i].$type;
    if($i<(count($str)-1)) $strm .=",";
    }
    return $strm;
   }        do you kown phpsu.com?
}
TITLE:tableManage.class.php
Copyright 2008 The PHPsu All rights reserved. This mirror generously provided by: .Hp Inc.
Last updated: Fri Jun 6 22:58:06 GMT-8 2008