Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在CI分页数据中添加复选框_Php_Codeigniter - Fatal编程技术网

Php 在CI分页数据中添加复选框

Php 在CI分页数据中添加复选框,php,codeigniter,Php,Codeigniter,如何在codeigniter驱动的应用程序中为分页数据的每行添加复选框? 这是我的密码 $this->load->library('pagination'); $config['base_url'] = base_url().'index.php/admin/editquestiontopics'; $config['total_rows'] = $this->db->count_all('tbl_a

如何在codeigniter驱动的应用程序中为分页数据的每行添加复选框? 这是我的密码

            $this->load->library('pagination');
            $config['base_url'] = base_url().'index.php/admin/editquestiontopics';
            $config['total_rows'] = $this->db->count_all('tbl_advice_topics');
            $config['per_page'] = '5';
            $config['full_tag_open'] = '<p>';
            $config['full_tag_close'] = '</p>';

            $this->pagination->initialize($config);

            $this->load->model('advice_topics_model');
            $data['results'] = $this->advice_topics_model->get_topics($config['per_page'],$this->uri->segment(3));

            $this->load->library('table');
            $this->table->set_heading('ID','Topic');

            $this->load->view('adminadvicetopics',$data);

        //this my model func()
    public function get_topics($num, $offset)
    {
    $query = $this->db->get('tbl_advice_topics',$num,$offset);
    return $query;
    }

       //this is my view code
        <?php echo $this->table->generate($results); ?>
    <?php echo $this->pagination->create_links(); ?>
$this->load->library('pagination');
$config['base_url']=base_url().'index.php/admin/editquestiontopics';
$config['total_rows']=$this->db->count_all('tbl_advice_topics');
$config['per_page']='5';
$config['full_tag_open']='';
$config['full_tag_close']=';
$this->pagination->initialize($config);
$this->load->model('advice\u topics\u model');
$data['results']=$this->advice\u topics\u model->get\u topics($config['per\u page'],$this->uri->segment(3));
$this->load->library('table');
$this->table->set_heading('ID','Topic');
$this->load->view('adminadvicetopics',$data);
//这是我的模型func()
公共函数get_topics($num,$offset)
{
$query=$this->db->get('tbl\u advice\u topics',$num,$offset);
返回$query;
}
//这是我的视图代码

这实际上与Codeigniter分页无关。它看起来更像是在视图“adminadvicetopics”中执行的操作,甚至是在模型中的函数“get_topics”中执行的操作

张贴这些代码,我们将更好地回答您的问题

编辑:现在我看到了您的代码,我看到您无法在视图中设置此选项。 如果您必须在此实例中使用codeigniter的表类,并且仍然希望使用查询结果作为输入,那么您必须在查询本身中添加复选框!这是一个相当混乱的方法,但看起来像这样:

public function get_topics($num, $offset)
{
    $sql = "SELECT 
               CONCAT('<input name=\"row_', `id`,  '\" type=\"checkbox\" value=\"row_', `id`,  '\" />') AS First_Column, 
               `Second_Column`, 
               `Third_Column` 
            FROM 
               `tbl_advice_topics` 
            LIMIT $offset, $num";
    $query = $this->db->query($sql);
    return $query;
}
公共函数获取主题($num,$offset)
{
$sql=“选择
CONCAT(“”)作为第一列,
`第二列`,
`第三列`
从…起
`tbl_建议_主题`
限制$offset,$num”;
$query=$this->db->query($sql);
返回$query;
}

更可接受的方法是将查询结果转换为表类可以使用的三维数组(如图所示)。然后,您可以在那里添加复选框,并对输出进行更多的控制。

这实际上与Codeigniter分页无关。它看起来更像是在视图“adminadvicetopics”中执行的操作,甚至是在模型中的函数“get_topics”中执行的操作

张贴这些代码,我们将更好地回答您的问题

编辑:现在我看到了您的代码,我看到您无法在视图中设置此选项。 如果您必须在此实例中使用codeigniter的表类,并且仍然希望使用查询结果作为输入,那么您必须在查询本身中添加复选框!这是一个相当混乱的方法,但看起来像这样:

public function get_topics($num, $offset)
{
    $sql = "SELECT 
               CONCAT('<input name=\"row_', `id`,  '\" type=\"checkbox\" value=\"row_', `id`,  '\" />') AS First_Column, 
               `Second_Column`, 
               `Third_Column` 
            FROM 
               `tbl_advice_topics` 
            LIMIT $offset, $num";
    $query = $this->db->query($sql);
    return $query;
}
公共函数获取主题($num,$offset)
{
$sql=“选择
CONCAT(“”)作为第一列,
`第二列`,
`第三列`
从…起
`tbl_建议_主题`
限制$offset,$num”;
$query=$this->db->query($sql);
返回$query;
}

更可接受的方法是将查询结果转换为表类可以使用的三维数组(如图所示)。然后,您可以在那里添加复选框,并对输出进行更多的控制。

是的,这仅在视图(而不是模型)中才有意义。正如你所说,它与分页无关,因为分页本身与数据的显示方式无关。嗨,伙计们,我编辑了我的第一篇文章并为此添加了所有代码,你现在能帮我在每一行中添加复选框吗?是的,这只在视图(而不是模型)中才有意义。正如你所说,它与分页无关,因为分页本身与数据的显示方式无关。嗨,伙计们,我编辑了我的第一篇文章,并为此添加了所有代码,你现在能帮我在每行中添加复选框吗?