Welcome Guest, Not a member yet? Register   Sign In
updating multiple values to mysql database using codeignter
#1

[eluser]dhaulagiri[/eluser]
my post data from form is coming as

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

and my model is

Code:
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, please help me in this code
#2

[eluser]srpurdy[/eluser]
You not setting the array properly. but I don't think you need the [ ] brackets either in the array itself.

You would do something like
Code:
$my_array = array();
Code:
$this->db->set($my_array);

Below is an example of a poll I did
Code:
#controller function
function submit()
{
    if($this->input->post('opt_id') == '0')
    {
    $this->errors->poll_no_selection();
    }
    else
    {
    $this->poll_model->submit_vote($this->input->post('userid'), $this->input->post('poll_id'), $this->input->post('opt_id'));
    redirect('/poll/iframe/' . $this->input->post('poll_id'));
    }
}
Code:
#model function
function submit_vote($userid, $pollid, $optid)
{
$array = array(
    'poll_id' => $pollid,
    'opt_id' => $optid,
    'userid' => $userid
);
$this->db->set($array);
$this->db->insert('poll_votes', $this->db->escape($_POST));




Theme © iAndrew 2016 - Forum software by © MyBB