开发者

Using the CodeIgniter tables library I am having an issue. It keeps printing an extra row with two columns in it

Here's the code in order of Model, Controller, Then View

// MODEL

function get_all_events()
{
    $query = $this->db->get('events');
    if($query->num_rows() > 0)
    {
        return $query;
    }
}

// CONTROLLER

    // get the data from the database
    $this->load->model('admin_model');
    $gettabledata = $this->admin_model->get_all_events();

    // create the table template
    $tbltmpl = array (
        'table_open'          => '<table border="0" cellpadding="0" cellspacing="0" width="100%">',
        'heading_row_start'   => '<tr>',
        'heading_row_end'     => '</tr>',
        'heading_cell_start'  => '<th>',
        'heading_cell_end'    => '</th>',
        'row_start'           => '<tr>',
        'row_end'             => '</tr>',
        'cell_start'          => '<td>',
        'cell_end'            => '</td>',
        'row_alt_start'       => '<tr>',
        'row_alt_end'         => '</tr>',
        'cell_alt_start'      => '<td>',
        'cell_alt_end'        => '</td>',
        'table_close'         => '</table>'
    );

    //开发者_开发百科 set the template
    $this->table->set_template($tbltmpl);

    // create the table headings
    $tableheadings = array (
        'ID','NAME','DATE','IMAGE','ADDED','MODIFIED','&nbsp;'
    );

    // set the table headings
    $this->table->set_heading($tableheadings);

    // create the table rows
    foreach($gettabledata->result() as $row)
    {
        $tablerow[] = $this->table->add_row(
            $row->event_id,
            $row->event_name,
            $row->event_date,
            $row->event_image,
            $row->event_added,
            $row->event_modified,
            'edit | delete'
        );
    }

    // generate the table and put it into a variable
    $data['table'] = $this->table->generate($tablerow);

// VIEW

<div class="block_content">

    <?php echo $table ?>

</div>

So, it'll print the table just fine, but it then also prints an extra row at the bottom. The extra row has two columns in it.


I've never used this library, but just a thought, it says in the userguide that you don't have to include all the options in the template. Have you tried not specifying the row_alt and cell_alt options in the template? Could they generate the unwanted rows?


I got it.

I didn't realize that since I was adding rows, I didn't need to include the $tablerow variable in the actually generate method. This was causing the extra row with columns.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜