您好我已經編寫了刪除記錄的代碼(只需將記錄的狀態從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>
嘗試重定向( '事業', '刷新'); – Vickel