我想为productId更新数据库中的记录数组。产品ID已存在于数据库中。下面是我的控制器功能:
public function insert_skus_from_csv()
{
//upload file
$target_dir = "documents/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
if(move_uploaded_file($_FILES['file']['tmp_name'],$target_file ))
{
chmod($target_file, 0777);
$file_contents = $this->csv_accesser->read_from_csv($target_file);
}
$sku_data = array();
$already_present_record=0;
foreach($file_contents as $key => $value)
{
$a = $this->sku_model->get_productID();
foreach ($a as $pid)
{
$product_id = $pid['ProductID'];
$sku_data[$key]['ProductIDType'] = 'UPC';
$sku_data[$key]['ProductID'] = $value[0];
$sku_data[$key]['SellerSKU'] = $value[1];
$sku_data[$key]['Description'] = $value[2];
$sku_data[$key]['KeyFeatures1'] = isset($value[3]) ? $value[3] : '';
$sku_data[$key]['KeyFeatures2'] = isset($value[4]) ? $value[4] : '';
$sku_data[$key]['KeyFeatures3'] = isset($value[5]) ? $value[5] : '';
$sku_data[$key]['KeyFeatures4'] = isset($value[6])? $value[6] : '';
$sku_data[$key]['KeyFeatures5'] = isset($value[7])? $value[7] : '';
$sku_data[$key]['KeyFeatures6'] = isset($value[8])? $value[8] : '';
$sku_data[$key]['Category'] = $value[9];
$sku_data[$key]['shopify_category'] = $value[10];
}
if(!empty($sku_data))
{
$a = $this->sku_model->get_productID();
foreach ($a as $pid)
{
$product_id = $pid['ProductID'];
$b = $this->sku_model->update_product_id($id_lists,$sku_data);
}
}
}
}
这是我的模特
<?php
class Sku_model extends CI_Model{
public function update_product_id($product_id,$sku_data)
{
//$this->db->where('ProductID', $product_id);
return $this->db->update_batch('product_skus',$sku_data,'ProductID');
// return $this->db->update('product_skus', $sku_data);
}
}
我尝试使用where条件,上面已经提到了,但是没有用。我使用了update_batch,但是数据库中只有这一行被更新了。我希望所有行都得到更新。 有人可以帮我解决,我哪里出了问题,该怎么办才能解决?
谢谢!