duanqiang9212 2016-11-10 17:28
浏览 28

只有数组中的最后一个值被发布到mysql数据库才需要发布所有值

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 )
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法