Welcome Guest, Not a member yet? Register   Sign In
where clauses duplicate when two queries following
#1

[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




Theme © iAndrew 2016 - Forum software by © MyBB