1

我正在做一个项目,该项目需要我在一列中显示所有数据。该表应该是 2 列,向下 7 行,其中一列将包含来自数据库的数据,而其他列将具有要检查的复选框。

我怎样才能制作这样的桌子?我尝试在数组中使用模板,然后加载它:

$this->table->set_template($tmp1);

但它不起作用,它仍然在一行中显示所有内容。

这是我的代码:

视图.php

<body> 
    <h1>Answer</h1>
    <div id="pagination">

<?php echo $this->table->generate($records);?>


<?php echo $this->pagination->create_links(); ?>

控制器.php

 function index()
       {            
        $this->load->library('pagination');
        $this->load->library('table');          
        $config['base_url'] = 'http://localhost/admin/index.php/survey/index';
        $config['total_rows'] = $this->db->get('save_survey')->num_rows();

        $config['per_page'] = 1;
        $config['num_links'] = 10;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';

        $this->pagination->initialize($config);
      //print_r($this->uri->segment());die;

        $data['records'] = $this->db->get('save_survey', $config['per_page'], $this->uri->segment(3, 0))->result_array();

        $data['pagination'] = $this->pagination->create_links();
        $this->load->view('survey_view', $data);

      }
}
?>
4

1 回答 1

1

如果要创建包含复选框的自定义表格

最好的方法是手动生成表,您可以通过以下方式执行此操作

$data['records'] = $this->db->get('save_survay', $config['per_page'], $this->uri->segment(3, 0))->result_array();
foreach($data['records'] as  $record) 
{
    $this->table->add_row(
                 form_checkbox($data, $value),
                 $record['col1'],
                 $record['col2']
    )
}

并且不要忘记自己设置标题

 $this->table->set_heading('h1','h2',...etc)
于 2013-02-15T09:40:31.093 回答