如何使用codeigniter的table class

How to use table class of codeigniter

在每一行中添加 edit/delete link 有什么技巧吗

Error in code : Cannot use object of type mysqli as array in C:\xampp\htdocs\CodeIgniter-3.0.6\application\views\admin.php on line 8

<?php 
 $table_property = array('table_open' => '<table cellpadding="2" cellspacing="1" class="table table-hover">');
  $this->table->set_heading('#Id','Username','Password','Name','Edit','Delete');
  $this->table->set_template($table_property);
  $new=$this->db->query("select * from tbl_admin");

  foreach($new as $row) {
  $links  = anchor('admin/edit/'.$row['User_ID'] ,'Edit');
  $links .= anchor('admin/delete/'.$row['User_ID'] , 'Delete');


$this->table->add_row(
    $row->User_ID,
    $row->Username,
    $row->Password,
    $row->Full_Name,
    $links
    );
}
echo $this->table->generate();
?>

query() 不是 return 直接包含所需对象的数组,而是 mysqli_result 对象;因此你不能这样使用它。

您可能想要做的是

while ($row = $new->fetch_assoc()) {
      // ...
}