2017-03-14 155 views
0

我想將我的ID散列添加到同一插入的我的散列列中。我在加入一個隱藏的東西,但我認爲不好,但是這個工作不需要觸發器,我怎樣才能在不添加新按鈕的情況下在php中執行此操作?使用散列生成插入語句

查詢它將根據id生成。

其中MD5(ID)然後isnert在列,我怎樣才能把所有一起= 表 ID散列 1 27669f3f141da48bfe5e6b7aa37c38f9

添加控制器

public function addProduct(){ 
     $descripcion = $this->input->post('description'); 
     $cost_price = $this->input->post('cost_price'); 
     $selling_price = $this->input->post('selling_price'); 
     $wprice = $this->input->post('wprice'); 
     $min_stock = $this->input->post('min_stock'); 
     $stock = $this->input->post('stock'); 
     $max_stock = $this->input->post('max_stock'); 
     $data = array(
      'hash' => $this->hash_id($descripcion), 
      'descripcion' => $descripcion, 
      'precio_compra' => $cost_price, 
      'precio_venta' => $selling_price, 
      'precio_mayoreo' => $wprice, 
      'existencia_minima' => $min_stock, 
      'existencia' => $stock, 
      'existencia_maxima' => $max_stock 
     ); 

     if ($data['existencia'] > $data['existencia_minima']) { 
      $this->json(array('min_stock' => 'el stock no puede ser mayor al min')); 
     }elseif ($data['existencia_maxima'] < $data['existencia']) { 
      $this->json(array('max_stock' => 'el stock no puede ser mayor al max')); 
     }else{ 
      if (!$this->products->isExistsProduct($data)) { 
       $this->products->addProduct($data); 
       $this->json(array('msg' => 'successfully added')); 
      }else{ 
       $this->json(array('duplicate' => 'product already exists')); 
      } 
     } 
    } 

模型

public function addProduct($data){ 
     $this->db->insert('storelte_articulos',$data); 
    } 

表格

<form id="update_product"> 
    <div class="row"> 
    <div class="form-group"> 
    <div class="col-xs-12"> 
     <label for="description">Name: </label> 
     <input type="text" class="form-control" id="description" name="description" title="product description" required> 
     <div> 
     </div> 
    </div> 
    <div class="row"> 
     <div class="form-group"> 
     <div class="col-xs-8 col-sm-6"> 
      <label for="cost_price">Cost Price: </label> 
      <div class="input-group"> <span class="input-group-addon">$</span> 
       <input type="text" class="form-control input-group-lg reg_name" id="cost_price" name="cost_price" title="cost_price" placeholder="Last name" required> 
      </div> 
     </div> 
     <div class="col-xs-8 col-sm-6"> 
      <label for="selling_price">Selling price: </label> 
      <input type="text" class="form-control input-group-lg reg_name" id="selling_price" name="selling_price" title="selling_price" placeholder="Last name" required> 
     </div> 
     </div> 
    </div> 
    <div class="row"> 
     <div class="form-group"> 
     <div class="col-xs-8 col-sm-6"> 
      <label for="wprice">Wholeprice: </label> 
      <input type="text" class="form-control" id="wprice" name="wprice" title="wprice" required> 
     </div> 
     <div class="col-xs-8 col-sm-6"> 
      <label for="min_stock">Min stock: </label> 
      <input type="text" class="form-control" id="min_stock" name="min_stock" title="min_stock" required> 
     </div> 
     </div> 
    </div> 
    <div class="row"> 
     <div class="form-group"> 
     <div class="col-xs-8 col-sm-6"> 
      <label for="stock">Stock: </label> 
      <input type="text" class="form-control" id="stock" name="stock" title="stock" required> 
     </div> 
     <div class="col-xs-8 col-sm-6"> 
      <label for="max_stock">Max stock: </label> 
      <input type="text" class="form-control" id="max_stock" name="max_stock" title="max_stock" required> 
     </div> 
     </div> 
    </div> 
</form> 

回答

0

使用這種方法 $這個 - > DB-> INSERT_ID() 和更新的數據(哈希)

得到插入ID