在codeigniter中插入后更新多行

时间:2019-05-27 17:51:50

标签: codeigniter rows

插入后,我想用($id.'mytext')更新字段,其中在db中该字段对所有行都是空的。

table name: peca
columns: 
id -autoincrement
A -varchar user insert
CB -varchar auto insert with update
MODEL WILL RETURN ALL ROWS WHERE CB=empty 

function model1() {
        $this->db->select('*');
        $this->db->from('peca');
        $this->db->where('CB', '');
        //$this->db->where('id', $fileid); 
        $query = $this->db->get();
        if ($query) {
            return $query->result();
        } else {
            return false;
        }
    }
MODEL WILL update in db where CB=empty 
function model2($dados = NULL) {
        if ($dados !== NULL) {
        //  extract($dados);
         $this->db->where('CB', '');
            $this->db->update('peca', $dados);
            return true;
        } else {
            return false;
        }
    }
CONTROLLER

 $this->load->model('model_peca');
            $resultadocadastropeca = $this->model_peca->model1($id);
            $data = 'id' => $id;
            $appointment = array('codigoean' => $data.'.PECA.');    
            $appointment = $this->model_peca->model2($appointment);

开始表 通过导入插入以前的值,因此只能在id存在后生成CB

id|CB      |
22|        |
31|        |

结果 我正在将CB更改为.PECA。在所有未通过CB = empty但每行$ id的行中

id|CB    |
22|.PECA.|
31|.PECA.|

预期

id|CB      |
22|22.PECA.|
31|31.PECA.|

1 个答案:

答案 0 :(得分:0)

我仍然不完全了解您想做什么,但是如果您想获取某列为空或为null的内容,

$this->db->select('id'); $this->db->where('CB', ''); $q = $this->db->get('peca'); if ($q->num_rows() == 0) { die('nothing to do here'); } $res = $q->result(); foreach ($res as $item) { $data[] = array('id' => $item->id, 'CB' => $item->id . '.PECA.'); } $this->db->update_batch('peca', $data, 'id');


根据您修改后的问题,这应该可行:

function rotateRight(img){

  var w = img.width;
  var h = img.height;
  var index, indexr;
  var img2 = createImage(w, h);

  img.loadPixels();
  img2.loadPixels();

  indexr = 0;

  for (let x = 0; x < w; x++) {

    for(let y = h - 1; y >= 0; y--) {

      index = (x+y*w)*4;
      img2.pixels[indexr] = img.pixels[index];
      img2.pixels[indexr + 1] = img.pixels[index+1];
      img2.pixels[indexr + 2] = img.pixels[index+2];
      img2.pixels[indexr + 3] = img.pixels[index+3];

      indexr += 4;

    }
  }

  img.updatePixels();
  img2.updatePixels();

  return img2;

}


function rotateLeft(img){

  var w = img.width;
  var h = img.height;
  var index, indexr;
  var img2 = createImage(w, h);

  img.loadPixels();
  img2.loadPixels();

  indexr = 0;

  for (let x = w - 1; x >= 0; x--) {

    for(let y = 0; y < h; y++) {

      index = (x+y*w)*4;
      img2.pixels[indexr] = img.pixels[index];
      img2.pixels[indexr + 1] = img.pixels[index+1];
      img2.pixels[indexr + 2] = img.pixels[index+2];
      img2.pixels[indexr + 3] = img.pixels[index+3];

      indexr += 4;

    }
  }

  img.updatePixels();
  img2.updatePixels();

  return img2;

}