zoukankan      html  css  js  c++  java
  • Thinkphp add addAll

    add用户添加一条数据。项目实例
    public function treeinsert(){
               $data=array();
               $data['id']='';
               $data['type']='0';
               $data['title']=$_REQUEST['name'];
               $data['level']=$_REQUEST['level'];
               $data['pid']=$_REQUEST['ids'];
               $data['sort']='0';
               $data['status']='1';
               $data['rules']='';
               $data['Mome']='';
               $data['remarks']='';
               $user=M('worktelgroup');
               $user->add($data);
    
          }
    
    addAll是往数据库中同时添加多条数据,数据为二维数组、同时二维数组的键由0开始,项目实例:
    public function telnode(){
               $itemid = I('post.itemid');
               $data=I('post.data');
               $insert=array();
               foreach ($data as $k => $v) {
                   $insert[$k]['id']='';
                   $insert[$k]['wtelid']=str_replace('s', '', $v['id']);
                   $insert[$k]['itemid']=$itemid;
               }
               //var_dump($insert);
               $user=M('item_worktel');
               $user->addAll($insert);
          }
    组成的$insert数据结构如下array(2) {
      [0]=>
      array(3) {
        ["id"]=>
        string(0) ""
        ["wtelid"]=>
        string(1) "2"
        ["itemid"]=>
        string(1) "9"
      }
      [1]=>
      array(3) {
        ["id"]=>
        string(0) ""
        ["wtelid"]=>
        string(2) "11"
        ["itemid"]=>
        string(1) "9"
      }
    }
  • 相关阅读:
    [HDU6793] Tokitsukaze and Colorful Tree
    [NOI2020]命运
    [NOI2020]美食家
    模拟9
    晚测2
    模拟8
    联考4
    模拟7
    模拟6
    关于数论
  • 原文地址:https://www.cnblogs.com/hjxcode/p/7202430.html
Copyright © 2011-2022 走看看