I have an HTML table full of inputs populated by data in a database table. I generate a form for each row as a separate table, and a submit button for each. I want the update button to update only the row associated with the generated form.
If I remove this->db->where('id', $id); from the model, it updates all rows in the table with the same info. With the where() call present, nothing is updated.
VIEW
<?php foreach($log->result() as $row): ?>
<?=form_open('hq/update_entry');?>
<table class="editLog">
<tr>
<td><?php
$data = array(
'name' => 'no',
'value' => $row->no
);
echo form_input($data);
?></td>
<td><?php
$data = array(
'name' => 'date',
'value' => $row->date
);
echo form_input($data);
?></td>
<td><?php
$data = array(
'name' => 'artist',
'value' => $row->artist
);
echo form_input($data);
?></td>
<td><?php
$data = array(
'name' => 'title',
'value' => $row->title
);
echo form_input($data);
?></td>
<td><?php
$data = array(
'name' => 'long',
'value' => $row->long
);
echo form_input($data);
?></td>
<td><?php
$data = array(
'name' => 'lat',
'value' => $row->lat
);
echo form_input($data);
?></td>
<td>
<?php
echo form_hidden('id', $row->id);
$data = array(
'class' => 'updateSubmit',
'value' => '✚'
);
echo form_submit($data);
?></td>
</tr>
</table>
<?=form_close();?>
CONTROLLER
public function update_entry()
{
$this->load->model('update_entry_model');
if ($query = $this->update_entry_model->update()) {
$this->index();
} else {
redirect('hq');
}
}
MODEL
class Update_entry_model extends CI_Model
{
public function update()
{
$data = array(
'no' => $this->input->post('no'),
'date' => $this->input->post('date'),
'artist' => $this->input->post('artist'),
'title' => $this->input->post('title'),
'long' => $this->input->post('long'),
'lat' => $this->input->post('lat')
);
$this->db->where('id', $id);
$this->db->update('entries', $data);
}
}