Habib Rehman Habib Rehman - 7 months ago 41
MySQL Question

Codeigniter query updating all rows instead of 1

I'm having problem in updating a row i'm doing it through ajax, the query is affecting all rows instead of a single id i have given

This is my Model Class function:

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;
return FALSE;


I have also checked the data i'm getting from ajax is right, but i guess there is some problem with query thing i even hardcoded the id value still it's updating all names instead of one.

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

This is the right way to put a where condition while updating a query.

There is a difference between get_where and where.

get_where will retrieve the data rows from the table, whereas where will add a condition