简体   繁体   English

无法使用Codeigniter PHP更新数据库中选定的框值

[英]Unable to update the selected boxes values in database using codeigniter php

Hi I am creating a view where I will be displaying the list of records from database along with boxes where a user selects checkboxes and click on Activate button. 嗨,我正在创建一个视图,其中将显示数据库中的记录列表以及用户选中复选框并单击“激活”按钮的框。 In the database I have given a separate column for featured blogs once user click on activate, these id columns should be updated as 1 and rest will be as 0. 在数据库中,一旦用户单击激活,我将为特色博客提供单独的列,这些id列应更新为1,其余列应更新为0。

View: 视图:

            <table>
                <thead>
                    <tr>
                        <th scope="col">Featured Blogs</th>
                        <th scope="col">S.No</th>
                        <th scope="col">Blog Title</th>
                        <th scope="col">Author</th>

                    </tr>
                </thead>

                <tbody>

                <?php if(isset($records) && is_array($records) && count($records)>0): ?>    
                <?php  $i=0;foreach($records as $r):$i++;?>     
                    <tr>
                        <td><input type="checkbox" name="checkbox" value="<?php echo $r->blog_id;?>" 
                        <?php if ($r->featured_blogs == 1) { echo 'checked="checked"'; }else { echo 'disabled="disabled"'; }?> ></td>                           
                        <td class="align-center"><?php echo $i;?></td>
                        <td><?php echo $r->blog_title;?></td>
                        <td><?php echo $r->username;?></td>

                    </tr>

                <?php endforeach ;endif;?>

                </tbody>
            </table>
            <div class="pagination"><?php echo $links; ?></div> 
            <a href="<?php echo base_url();?>/blogs/active" class="button">Activate</a>

        </div>
    </div>

Controller: 控制器:

function active()
{
    $this->blogs_model->active($this->uri->segment(3));
    $this->flash->success('<h2>Successfully Activated the record.<h2>');
    redirect('blogs');
}

Model: 模型:

function activate($blog_id)
{
    $data=array('status'=>1);
    $this->db->where(array('blog_id'=>$blog_id));
    $this->db->update('blogs',$data);
}
function active()
{
    $this->blogs_model->active($this->uri->segment(3));
    $this->flash->success('<h2>Successfully Activated the record.<h2>');
    redirect('blogs');
}


function active($blog_id)
{
    $data=array('status'=>1);
    $this->db->where(array('blog_id'=>$blog_id));
    $this->db->update('blogs',$data);
}

on your controller you called the model and it's function as active($this->uri->segment(3)) but in your model you called it as function activate($blog_id) you should need to change it 在您的控制器上,您调用了该模型,并且该模型的功能为active($this->uri->segment(3))但是在您的模型中,您将该模型称为function activate($blog_id)您需要对其进行更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM