CodeIgniter Forums
[SOLVED] Update multiple inputs with the same name - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [SOLVED] Update multiple inputs with the same name (/showthread.php?tid=54256)



[SOLVED] Update multiple inputs with the same name - El Forum - 08-30-2012

[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[]">




[SOLVED] Update multiple inputs with the same name - El Forum - 08-30-2012

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


[SOLVED] Update multiple inputs with the same name - El Forum - 08-30-2012

[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


[SOLVED] Update multiple inputs with the same name - El Forum - 08-30-2012

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



[SOLVED] Update multiple inputs with the same name - El Forum - 08-30-2012

[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'





[SOLVED] Update multiple inputs with the same name - El Forum - 08-30-2012

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

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



[SOLVED] Update multiple inputs with the same name - El Forum - 08-30-2012

[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


[SOLVED] Update multiple inputs with the same name - El Forum - 08-30-2012

[eluser]puffnstuff[/eluser]
-