I am currently using codeigniter to grab data from a MySQL table and displaying it on screen. The data is being displayed in an html form so when the user logs into my website the data from the database is already being displayed.
What I would like to happen is if the user changes some of the data in the fields and then pushes the upload button the data should be pushed back to the database and if they refresh the screen their changes should show.
At the moment when I go to push the changes only the last values in the array are being sent. How can I have all of the values in my array sent to the MySQL database. Below is my code for the view, controller, and model. Any help is greatly appreciated!
View
<?php
$i=0;
echo form_open('site/push_data');
foreach($query as $row):
echo form_input('lab['.$i.'][priority]', $row->priority);
echo form_input('lab['.$i.'][item]', $row->item);
echo form_input('lab['.$i.'][equipment]', $row->equipment);
echo form_input('lab['.$i.'][post]', $row->post);
echo form_input('lab['.$i.'][item_type]', $row->item_type);
$i++;
endforeach;
echo form_submit('submit', 'Push');
echo form_close();
?>
<h4><?php echo anchor('login/logout', 'Logout'); ?></h4>
Controller
function push_data()
{
$this->load->model('display_lab_data');
$this->display_lab_data->writeToDB($this->input->post('lab'));
}
Model
function writeToDB($data)
{
for($i = 0; $i < 6; $i++)
{
print_r($_POST['lab'][$i]);
$this->db->update_batch('lab_priority_list', $_POST['lab'][$i]);
}
/*print_r($_POST['lab']);
foreach($_POST['lab'] as $Value)
{
$this->db->update('lab_priority_list', $Value);
}*/
}
Current content of my array
Array ( [priority] => 600 [item] => 78920 [equipment] => machine 53 [post] => blidoolpoop [item_type] => 1 ) Array ( [priority] => 600 [item] => 78920 [equipment] => machine 53 [post] => blidoolpoop [item_type] => 1 ) Array ( [priority] => 600 [item] => 78920 [equipment] => machine 53 [post] => blidoolpoop [item_type] => 1 ) Array ( [priority] => 600 [item] => 78920 [equipment] => machine 53 [post] => blidoolpoop [item_type] => 1 ) Array ( [priority] => 600 [item] => 78920 [equipment] => machine 53 [post] => blidoolpoop [item_type] => 1 ) Array ( [priority] => 600 [item] => 78920 [equipment] => machine 53 [post] => blidoolpoop [item_type] => 1 )