Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.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
Php Codeigniter查询更新所有行而不是1_Php_Mysql_Ajax_Codeigniter - Fatal编程技术网

Php Codeigniter查询更新所有行而不是1

Php Codeigniter查询更新所有行而不是1,php,mysql,ajax,codeigniter,Php,Mysql,Ajax,Codeigniter,我在通过ajax更新行时遇到问题,查询影响的是所有行,而不是我给出的单个id 这是我的模型类函数: public function edit_season($data) { // echo $a = json_encode($data); // echo $a->id; // die(); $this->db->get_where('seasons', array('season_id ' => 11 )); $query = $

我在通过ajax更新行时遇到问题,查询影响的是所有行,而不是我给出的单个id
这是我的模型类函数:

public function edit_season($data)
{
    // echo $a = json_encode($data);
    // echo $a->id;
    // die();

    $this->db->get_where('seasons', array('season_id ' => 11 ));
    $query = $this->db->update('seasons',array('names ' => $data['name'] ));

    if ($query) 
    {
        return $query;
    }
    else
    {
        return FALSE;
    }

}

我还检查了我从ajax获得的数据是否正确,但我猜查询中存在一些问题,我甚至硬编码了id值,但它仍在更新所有名称,而不是一个名称。

您不应该调用get\u where,而是使用where:

$this->db->where('season_id', 11);
$query = $this->db->update('seasons',array('names ' => $data['name'] ));
您也可以在一行中完成:

$query = $this->db->update('seasons',array('names ' => $data['name']), "season_id = 11");
试试这个

 $this->db->where('seasons', array('season_id ' => 11 ));
 $query =  $this->db->update('seasons',array('names ' => $data['name'] ));
这是在更新查询时放置
where
条件的正确方法

get_where
where
之间存在差异


get\u其中
将从表中检索数据行,而
where
将添加一个条件

美元数据的格式是什么?它是json数组吗?
其中
不需要表名作为参数。它有两个参数,第一个作为列名,第二个作为列值。或者是一个包含键值对的数组,其中key是列名,value是列值这是正确答案。您还可以在更新查询中直接包含where语句:
$query=$rows->update('seasures',array('names'=>$data['name']),array('seasure_id'=>11))@jtheman,没错。刚刚尝试为新手提供一个简单的解决方案,在哪里定义了
$rows
?您需要将
$row
替换为
$this->db
。编辑了答案
$this->db->where('season_id', 11));
$query = $this->db->update('seasons', array('names ' => $data['name']));