DedeCms批量写入数据的函数
dedecms如果是新闻与软件表我们只要操作三个表就可以了,如果我们要对批量插入的数据设置未设置状态只要在主表字段arcrank设置为-1就可以,下面看一个例子,代码如下:
-
- class IndexAction extends Action {
- public function index(){
- $id = $this->_get('id'); $endid = $this->_get('endid');
- $typeid = 9;
- $db = M(); if(!$id || !$endid){
- $listend = $db->table('dede_archives')->limit(1)->order('id desc')->find();
- exit('no id and endid id must start big from '.$listend['id']);
- }
- $list = $db->table('tb1')->where('status=0')->find();
- if($list){
- $time=time();
- $r1= $db->query("INSERT INTO `dede_arctiny` VALUES(".$id.", ".$typeid.", '0', 0, 1, ".$time.", ".$time.", 1)");
- $data2['arcrank']=-1;
- $data2['title']=$list['title'];
- $data2['typeid']=$typeid;
- $data2['id']=$id; $data2['pubdate']=$time;
- $data2['senddate']=$time; $data2['sortrank']=$time;
- $data2['mid']=1;
- $data2['dutyadmin']=1;
- $data2['weight']=1;
- $r2=$db->table('dede_archives')->add($data2);
- if($r2>0){
- $r3= $db->query('INSERT INTO `dede_addonarticle` VALUES('.$id.', '.$typeid.', "'.$list['content'].'", "", "", "127.0.0.1")');
- $r4 = $db->table('tb1')->where("id = ".$list['id'])->setField('status',1);
- if($r4){
- $nextid = $id+1;
-
- echo 'ok '.$id;
- echo 'next '.$nextid; if($endid==$id) exit('<br>the end id!');
- echo"<script>window.location.href='/Sphp/index.php?s=/Index/index/id/".$nextid."/endid/".$endid."'</script>";
- }
- }
-
-
- exit;
-
- }else{ echo 'no article yet'; }
-
-
-
- }
- }