So I'm new to PHP and MySQL generally, and MVC applications. Forgive me if this is a question that has been answered already, I couldn't find anything that was crystal clear and showed the complete MVC flow of this.

我对PHP MySQL和MVC应用程序都不熟悉。如果这是一个已经回答过的问题,请原谅我,我找不到任何非常清楚的内容,并显示了完整的MVC流程。

So I have an HTML table full of inputs populated by data in a, 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.

因此,我有一个HTML表,其中充满了数据填充的输入,我为每一行生成一个表单作为一个单独的表,并为每一行生成一个submit按钮。我希望update按钮只更新与生成的表单相关联的行。

If remove this->db->where('id', $id); from the model it updates all rows in the table with the same info, with it present nothing is updated.

如果删除这个- > db - >(id,id美元);从模型中,它更新表中的所有行,并提供相同的信息,但没有更新任何内容。

Any help or an alternative method for achieving this would be most appreciated. The controller function is also not pretty bad I think.

任何帮助或另一种实现这一目标的方法都是最值得赞赏的。我认为控制器的功能也不坏。

Thank you.

谢谢你!

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

控制器

function update_entry()
{
    $this->load->model('update_entry_model');

    if($query = $this->update_entry_model->update())
    {
        $this->index();
    }
    else
    {
        redirect('hq');
    }
}

MODEL

模型

<?php
    class Update_entry_model extends CI_Model {
        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);
        }
    }

1 个解决方案

#1


3

Without doing further investigation, I see that in the model function update(), you are missing

没有进一步的调查,我看到在模型函数update()中,您丢失了。

$id = $this->input->post('id');

The reason why adding this->db->where('id', $id); doesn't update anything is because $id is not currently set to any value.

添加这个->db->的原因是('id', $id);不更新任何东西是因为$id当前没有设置为任何值。

更多相关文章

  1. 来自php表单的样式电子邮件
  2. 请问如何用php实现表单提交后以邮件的形式把表单内容发到邮箱中
  3. 如何在jQuery Mobile页面中提交表单?
  4. Symfony2 -从数据库中提取数据并以表单形式显示
  5. [CI]CodeIgniter视图 & 模型 & 控制器
  6. laravel 框架自带表单验证
  7. AJAX学习之提交表单
  8. 在提交注册表单时使用jQuery显示错误
  9. Laravel在模型保存中两次插入差异

随机推荐

  1. C#怎么将 HTML转换为图片或 PDF?
  2. C#开发微信门户及应用(一)之微信接口的如
  3. Enum扩展特性实例代码
  4. C#中关于扩展方法的实例分析
  5. 详细介绍一个.net开源权限管理系统
  6. 总结一些编码和设计原则实例
  7. C#中如何格式化json字符串的方法分析
  8. ASP.NET Core 应用程序发布命令实例
  9. 分享在C#中时间戳是怎么转换的?
  10. 如何使用C#来制作扫雷游戏的图文代码教程