在codeigniter中删除后删除记录php

问题描述:

您好我已经编写了删除记录的代码(只需将记录的状态从1更改为0)。删除工作正常。在codeigniter中删除后删除记录php

但问题是,删除记录后,它不会立即删除后,我点击刷新按钮。它将从列表中删除记录。这是我为此编写的代码。

控制器:

function index() 
{  
$data['records'] = $this->career_model->get_jobs_list(); 
$data['mainpage']='career'; 
$data['mode']='all'; 
$this->load->view('templates/template',$data); 
} 
function delete()     
{  

    $this->career_model->delete($this->uri->segment(3));      
    $this->flash->success('<h2>Successfully deleted the record.<h2>'); 
    redirect('careers');     
} 

型号:

function get_jobs_list() 
{ 
    $this->db->Select('jobs_list.*'); 
    $this->db->From('jobs_list'); 
    $this->db->where(array('jobs_list.status'=>1)); 
    $q=$this->db->get(); 
    if($q->num_rows()>0)  
    {  
     return $q->result(); 
    } 
     else 
     { 
    return false; 
    } 
} 
function delete($jobs_id) 
{ 
    $data=array('status'=>0); 
    $this->db->where(array('jobs_id'=>$jobs_id)); 
    $this->db->update('jobs_list',$data); 
} 

查看:

<div id="mydiv">  
     <?php echo $this->flash->display('success', TRUE);?> 
    </div> 
    <script> 
     setTimeout(function() { 
      $('#mydiv').hide('fast'); 
     }, 10000); 
    </script> 

    <div id="main">   
     <div class="full_w"> 
      <div class="h_title"> 
       <div class="lefttitle fl"> 
        Categories 
       </div> 
       <div class="rightbutton fr"> 
        <a class="button add" href="<?php echo site_url()?>/careers/add">Add </a> 
        <a class="button del" href="<?php echo site_url()?>/careers/deactivated">Deactivated </a>      
       </div> 
      </div> 
      <table> 
       <thead> 
        <tr> 
         <th scope="col">S.No</th> 
         <th scope="col">Job List</th>       
         <th scope="col" style="width: 65px;">Modify</th> 
        </tr> 
       </thead> 

       <tbody> 
       <?php if(isset($records) && is_array($records) && count($records)>0): ?>  
       <?php $i=0;foreach($records as $r):$i++;?>  
        <tr> 
         <td class="align-center"><?php echo $i;?></td> 
         <td><?php echo $r->job_name;?></td> 

         <td> 
          <a href="<?php echo site_url();?>/careers/edit/<?php echo $r ->jobs_id ;?>" class="table-icon edit" title="Edit"></a> 
          <a href="<?php echo site_url();?>/careers/delete/<?php echo $r ->jobs_id ;?>" onclick="return confirm('Are you sure to delete');" class="table-icon delete" title="Delete"></a> 
         </td> 
        </tr> 
       <?php endforeach ;endif;?> 
       </tbody> 
      </table> 

     </div> 
    </div> 
    <div class="clear"></div> 
+0

尝试重定向( '事业', '刷新'); – Vickel

尝试redirect('/careers', 'refresh');

docs

可选的第二个参数允许您强制使用特定的 重定向方法。可用的方法是自动,位置和刷新,在IIS服务器上位置更快但不太可靠。 默认为auto,它将尝试基于服务器环境智能地选择 方法。

+0

直到我点击重新加载符号它不工作 – user8001297

+0

'职业'的路线如何? – Vickel

+0

我没有得到你的路线 – user8001297

尝试在模型get_jobs_list()函数中添加单引号。

变化$this->db->where(array('jobs_list.status'=>1));$this->db->where(array('jobs_list.status'=>'1'));

+0

不工作 – user8001297