0

my post data from form is coming as

Array
(
    [radiogroup_1] => 1
    [radiogroup_2] => 4
    [radiogroup_4] => 11
    [submit] => submit
)

and my model is

 function add_votes(){

    foreach($POST[] as $k=> $v){
    $id = $v;
    }

    $this->db->where('answerid','radiogroup_'. $id );

    $this->db->set('votes', 'votes+1',FALSE);
    $this->db->update('vote_table');


 }

apparently, it's not working.

1
  • What's your question here? What are you trying to accomplish. It's confusing, you know! Also you apparently have a logical error in your code. $id is always equals to 'submit' after the foreach Commented Jul 10, 2011 at 18:28

2 Answers 2

1

Maybe

function add_votes(){
    foreach($_POST[] as $k=> $v){
        $this->db->where('answerid','radiogroup_'. $v );
        $this->db->set('votes', 'votes+1',FALSE);
        $this->db->update('vote_table');
    }
}

or

function add_votes(){
    foreach($_POST[] as $k=> $v){
        $this->db->where('answerid', $v );
        $this->db->set('votes', 'votes+1',FALSE);
        $this->db->update('vote_table');
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Dont need to foreach to update. Just use update the table one time.

 function add_votes(){
 $radiogroup_1=$this->input->post('radiogroup_1');
 $radiogroup_2=$this->input->post('radiogroup_2');
 $radiogroup_4=$this->input->post('radiogroup_4');
$data=array('radiogroup_1'=>$radiogroup_1,'radiogroup_2'=>$radiogroup_2,'radiogroup_4'=>$radiogroup_4);
$this->db->where('answerid','radiogroup_'. $id );
$result=$this->db->update('vote_table',$data);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.