2017-08-13 40 views
0
<table class="table admin-table list-table nurserytwo-table"> 
<thead> 
    <tr> 
     <td>ID</td> 
     <td>Name</td> 
     <td>Code</td> 
     <td>Active</td> 
     <td>Edit</td> 
    </tr> 
</thead> 
<tbody> 
    <?php foreach($nurseries->result() as $nursery) { ?> 
    <tr> 
     <td><?php echo $nursery->id; ?></td> 
     <td><?php echo $nursery->name; ?></td> 
     <td><?php echo $nursery->code; ?></td> 
     <td><?php echo set_bool($nursery->active); ?></td> 
     <td><span class="glyphicon glyphicon-edit"></span> <?php echo 
anchor('admin/nurseries/edit_nursery/'.$nursery->id, 'Edit', 'class="edit- 
link"'); ?></td> 
    </tr> 
    <?php } ?> 
</tbody> 
</table> 

這是我目前的表代碼,我有一個很好的看看,看看我是否可以解決如何做到這一點但我對PHP真的很陌生,看起來似乎無法理解它。我需要在編輯之後添加一個刪除按鈕,我知道我可以通過delete.php來完成,但不知道從哪裏開始。任何幫助將非常感激。需要添加一個刪除按鈕到一個HTML表格從數據庫中刪除記錄與消息

更新:

這是我目前:

 }elseif($action == "delete_nursery_course"){ 

     if($id) { 

      $q = $this->db->where('id', $id)->delete('nursery_courses'); 
      if($this->db->affected_rows() > 0) { 
       if($this->input->is_ajax_request()) { 
        $this->output->enable_profiler(FALSE); 
        echo "SUCCESS"; die(); 
       }else{ 
        set_flash_message('Nursery deleted successfully.', 
'success'); 
       } 
      }else{ 
       if($this->input->is_ajax_request()) { 
        $this->output->enable_profiler(FALSE); 
        echo "Something went wrong. Please try again."; die(); 
       }else{ 
        set_flash_message('Something went wrong. Please try 
again.', 'error'); 
       } 
      } 

這裏是HTML:

<table class="table admin-table list-table nurseryone-table"> 

<thead> 
    <tr> 
     <td>ID</td> 
     <td>Name</td> 
     <td>Colour</td> 
     <td>Active</td> 
     <td>Edit</td> 
     <td>Delete</td> 
    </tr> 
</thead> 
<tbody> 
    <?php foreach($nursery_courses->result() as $nursery_course) { ?> 
    <tr> 
     <td><?php echo $nursery_course->id; ?></td> 
     <td><?php echo $nursery_course->name; ?></td> 
     <td><div style="background:<?php echo $nursery_course->colour; ?>" 
class="course-colour"></div></td> 
     <td><?php echo set_bool($nursery_course->active); ?></td> 
     <td><span class="glyphicon glyphicon-edit"></span> <?php echo 
anchor('admin/nurseries/edit_nursery_course/'.$nursery_course->id, Edit', 'class="edit-link"'); ?></td> 
     <td> 
<span class="glyphicon glyphicon-trash"></span> <?php echo 
anchor('admin/nurseries/delete_nursery_course/'.$nursery_course->id, 
'delete', 'class="delete-link"'); ?></td> 
    </tr> 
    <?php } ?> 
</tbody> 
</table> 
+0

是你的編輯鏈接的工作? –

+0

這是耶。你想讓我發佈代碼嗎? – mischiefbec

+0

是的,這可能會有所幫助。 –

回答

0

你可以只使用HTML和JavaScript與jQuery使用Ajax請求編輯和刪除按鈕。

HTML:

<td class="text-right"> 
    <a class="edit btn btn-sm btn-default" href="javascript:;"> 
     <i class="icon-note"></i> 
    </a> 
    <a class="delete btn btn-sm btn-danger" href="javascript:;"> 
     <i class="icons-office-52"></i> 
    </a> 
</td> 

而在你的JavaScript文件,你必須定義這個按鈕的onclick事件。

這裏有一個例子Plunker用HTML和JavaScript代碼: Editable Table

你也可以使用jQuery的數據表,使其更容易,更好。

希望它能幫助你。