Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Codeigniter中更新具有唯一id的行_Codeigniter - Fatal编程技术网

如何在Codeigniter中更新具有唯一id的行

如何在Codeigniter中更新具有唯一id的行,codeigniter,Codeigniter,我有一个表,它有一个customer_number字段,有些数字重复多次,但我只想得到该字段中唯一的数字 public function set_unique() { $e = $_POST['e']; if($e == 1) { $one = $this->db->get('calls_details'); foreach($one->result() as $data) { $two =

我有一个表,它有一个customer_number字段,有些数字重复多次,但我只想得到该字段中唯一的数字

public function set_unique()
{
    $e = $_POST['e'];
    if($e == 1)
    {   
        $one = $this->db->get('calls_details');
        foreach($one->result() as $data) {
            $two = $this->db->where('Customer_Number', $data->Customer_Number)
                            ->get('calls_details');
            if($two->num_rows() == 1) {
                foreach($two->result() as $data2) {
                   $three = $this->db->where('Customer_Number', $data2->Customer_Number)
                                        ->update('calls_details', ['unique_id'=>1]);

                }
            }
          }    
       }   
    }
}

我想更新字段unique\u data=1,哪一行有唯一的customer\u编号您需要另一个id作为unique或autoincrement,通过它您可以轻松更改一条特定记录。将您的客户号视为重复的,因此更新应基于此id。我有一个唯一的id字段,但我想获取所有客户号,这在您在问题中提到的所有禁忌中都是唯一的,有些数字重复多次。不管怎样,您都需要按照我将要回答的方式来做。从calls\u details中选择customer\u number,其中customer\u number在calls\u details组中按countcustomer\u number=1的customer\u number选择customer\u number;使用此查询我已经用我的代码编辑了我的问题,我希望你能理解我想做什么。@TarunBhardwaj好吧,你的代码有很多混乱,不太清楚。其次,在foreach之后,我认为您应该使用data2->customer_number而不是“$data->customer_number”@TarunBhardwaj ok您可以共享相关文件和db表吗?如果可能,请让我知道我可以共享我的emil.hmmmmm ok,然后共享您在请求中传递的参数,我将尝试更新代码/answer@TarunBhardwaj是的,当然。它的ping@naveedramzan.com
// defining array in which we get form values
$dataDB = ['first_name' => $this->input->post('first_name'),
           'second_name' => $this->input->post('second_name'),
           'email' => $this->input->post('email'),
            ];

// load model
$this->load->model('Customer');

//set record id, which we need to be updated
$this->Customer->id = $uniqueCustomerIDNumber;

//save record
$this->Customer->save();