Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Update multiple inputs with the same name
#1

[eluser]puffnstuff[/eluser]
edit: got the answer for anybody who finds this I have updated with the correct way to update inputs with the same name in a loop...

Controller
Code:
$i=0;
foreach ($this->input->post('skill') as $cat)
{
    $this->db->where('id', $i)->update('skills', array('skill' => $cat));
    $i++;
}


Model
Code:
function update_record($data)
{

    $this->db->update('skills', $data);
   }

View

Quote:<input type="text" name="skill[]">

#2

[eluser]xtremer360[/eluser]
I notice you don't even call the updated_record function.
#3

[eluser]puffnstuff[/eluser]
[quote author="xtremer360" date="1346340227"]I notice you don't even call the updated_record function.[/quote]

Changed the controller to this
Code:
$i = 0;


foreach ($this->input->post('skill') as $cat) {
    $data[$i++]['skill'] = $cat;

}


$this->main_model->update_record('skill', $data);

No error but nothing is entering


I think I need $this->db->where but I have no clue how to pull the id for each individual input
#4

[eluser]xtremer360[/eluser]
I"m thinking it should be $this->main_model->update_record($i); but I could be wrong.
#5

[eluser]puffnstuff[/eluser]
[quote author="xtremer360" date="1346360651"]I"m thinking it should be $this->main_model->update_record($i); but I could be wrong.
[/quote]

Getting:

Unknown column '1' in 'field list'


#6

[eluser]xtremer360[/eluser]
In that case try replaying $i with something like:

Code:
$this->main_model->update_record('whatever field name is', $i);
#7

[eluser]puffnstuff[/eluser]
[quote author="xtremer360" date="1346361991"]In that case try replaying $i with something like:

Code:
$this->main_model->update_record('whatever field name is', $i);
[/quote]

Noticing it is just clearing out the data and not adding the info I input
#8

[eluser]puffnstuff[/eluser]
-




Theme © iAndrew 2016 - Forum software by © MyBB