【问题标题】:How to update sql table where id is in array codeigniter?如何更新id在数组codeigniter中的sql表?
【发布时间】:2018-02-27 03:00:45
【问题描述】:

我有这样的数组ID,

Array ( [0] => 1013 [1] => 1012 [2] => 1011 [3] => 1010 )

我想通过这些 id 更新我的表用户, 这是我的控制器代码

public function index()
{
    $id = $this->input->post('check_list');
    print_r($id); // just try to check output value
    $this->template->load('v_t','v_e', $data);
}

谢谢。

【问题讨论】:

  • 到目前为止你取得了什么成就?
  • @SalimIbrogimov 感谢您的回复,我的问题解决了 :)

标签: php sql arrays sql-server codeigniter


【解决方案1】:

你可以像下面这样使用 where_in

$this->db->where_in("id", $ids);
$this->db->update("tableName", $data);

用你的表名和列名更改上面的代码。

【讨论】:

    【解决方案2】:

    谢谢大家,我刚刚找到了答案,这里是我的控制器代码,用于通过数组 id 更新 sql

    public function update()
    {
        $this->load->database();
    
        foreach($_POST['check_list'] as $checkbox) {
            $data = array(
                    'STATS' => 'A');
            $this->db->where('ID', $checkbox);
            $this->db->update('USERS', $data);
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多