Answer the question
In order to leave comments, you need to log in
Why does the loop enter the same values five times?
public function edit_rating($id,$dateid,$obj){
$result = $this->get_pupils($id);
$pupils = array();
foreach ($result as $pupil)
$pupils[] = $pupil['id_user'];
for($i=0,$j=0;$i<count($pupils),$j<count($this->input->post('rating[]'));$i++,$j++){
$this->db->where('id_journal',$id);
$this->db->where('id_object',$obj);
$this->db->where('id_pupil',$pupils[$i])
$this->db->where('date',$dateid);
$this->db->set('rating',$this->input->post("rating[$j]"));
$this->db->update('view_journal');
}
}
Answer the question
In order to leave comments, you need to log in
Your code is a mess. You don't understand what's going on there, much less we.
However:
1) You are using the word "inject" which is most likely $this->db->insert and not $this->db->update
2) The implementation of $this->db is not clear, it looks like you once you reassign where and set for 5 update requests, and the execution of the requests themselves is called somewhere else. Perhaps you should have something like:
$db = $this->db->getNewInstance(); // возможно $db = $this->db->update('view_journal');
$db->where('id_journal', $id);
$db->where('id_object', $objectID);
$db->where('id_pupil', $pupilID);
$db->where('date', $date);
$db->set('rating', $rating);
$db->update('view_journal');
$db->exec();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question