2015-02-08 43 views
0

控制器我有一個tabluar形式表我需要放置複選框在它和一些功能來執行

class Category extends Admin_Controller { 
    public function __construct() { 
      parent::__construct(); 
      $this->load->model('category_model'); 
     } 
    public function index(){ 
     $data['select'] = $this->category_model->getinfo(); 
     $this->load->view('category_view', $data); 
    } 
    } 
?> 

模型

function getinfo(){ 
     $query = $this->db->get('user'); 
     return $query; 
} 

視圖

<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <title>Untitled Document</title> 
    </head> 
    <table border="1"> 
     <tbody> 
     <tr> 
      <td>Id</td> 
      <td>Name</td> 
      <td>lastname</td> 
     </tr> 
     <?php 
     foreach ($select->result() as $row) 
     { 
      ?><tr> 
      <td><?php echo $row->id;?></td> 
      <td><?php echo $row->name;?></td> 
      <td><?php echo $row->lastname;?></td> 

      </tr> 
     <?php } 
     ?> 
     </tbody> 
    </table> 
<body> 
</body> 
</html> 

我需要放置多個複選框,所以我可以通過點擊刪除數據我也必須一次檢查多個複選框(單一檢查並檢查所有兩個)。

回答

1
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Untitled Document</title> 
</head> 
<body> 
<table border="1"> 
    <tbody> 
    <tr> 
     <td>Id</td> 
     <td>Name</td> 
     <td>lastname</td> 
     <td>*</td> 
    </tr> 
    <?php 
    foreach ($select->result() as $row) 
    { 
     ?><tr> 
     <td><?php echo $row->id;?></td> 
     <td><?php echo $row->name;?></td> 
     <td><?php echo $row->lastname;?></td> 
     <td><?php echo form_checkbox('action[]', $row->id); ?></td> 
     </tr> 
    <?php } 
    ?> 
    </tbody> 
</table> 
</body> 
</html> 

當您發佈此信息時,您將獲得需要執行操作的ID數組。

+0

在行動中應該提到的 – 2015-02-08 13:42:17

+0

它顯示了我的表單標記錯誤致命錯誤:調用未定義的函數form_checkbox() – 2015-02-08 13:44:07

+0

@PranavShah您需要在加載此視圖的控制器函數中加載表單助手$ this-> load - > helper('form');' – 2015-02-08 13:51:05

相關問題