CodeIgniter Forums
where clauses duplicate when two queries following - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: where clauses duplicate when two queries following (/showthread.php?tid=50636)



where clauses duplicate when two queries following - El Forum - 04-02-2012

[eluser]Unknown[/eluser]
Hi,

can't find a solution.

I'm running a first query that counts pupils and then I update groups table with pupils number.

Code:
/**
* count_eleves
*/
public function count_eleves($groupe)
{
$query = $this->db->get_where('eleves', array('eleve_gr_id'=>$groupe));
$nb_eleves = $query->num_rows();
return $nb_eleves;
}
  
/**
* update_count_eleves
*
*/
public function update_count_eleves($groupe)
{
   if($this->count_eleves($groupe)>0)
{
  $this->db->where('gr_id', $groupe);
  $dbdata = array(
    'gr_nb_eleves'=>$this->count_eleves($groupe),
    );
    
    
                $this->db->update('groupes', $dbdata);
}
else
{
  return FALSE;
}
}
Here is the error message I get
Code:
Error Number: 1054

Champ 'gr_id' inconnu dans where clause

SELECT * FROM (`eleves`) WHERE `gr_id` = '11' AND `eleve_gr_id` = '11'

Filename: C:\Program Files\EasyPHP-5.3.6.0\www\stage\system\database\DB_driver.php

Line Number: 330
As you can see where clause from the fisrt query is repeated in the second.



Any solution would be welcome.

Thank