开发者

add checkboxes in CI paginated data

how to add checkbox on each row of a pagin开发者_StackOverflow社区ated data in codeigniter powered app ? here's my code

            $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 doesn't really have anything to do with Codeigniter pagination. It seems more like something you would do in the view 'adminadvicetopics' or even the function 'get_topics' in your model.

Post the code for those and we'll be better equipped to answer your question.

EDIT: Now I've seen your code I see you are not going to be able to set this in your views. If you must use codeigniter's table class in this instance and still want to use the query result as the input then you will have to add the checkboxes in the query itself! This is a rather messy method but would look something like this:

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;
}

A more acceptable method would be to turn the query results into a 3 dimensional array that the table class can use (as shown here). You can then add the checkbox there and have much more control over your output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜