CodeIgniter Forums
HTML Table class? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: HTML Table class? (/showthread.php?tid=35308)

Pages: 1 2


HTML Table class? - El Forum - 10-25-2010

[eluser]anna16[/eluser]
Hi guys

I followed the User Manual about the Table clas.
and tested this codes below,
Code:
$this->load->library('table');

$data = array(
             array('Name', 'Color', 'Size'),
             array('Fred', 'Blue', 'Small'),
             array('Mary', 'Red', 'Large'),
             array('John', 'Green', 'Medium')
             );

echo $this->table->generate($data);

I don't understand why the output i iterated 3 times.
Suggestion please.

Thanks in advanced.


HTML Table class? - El Forum - 10-25-2010

[eluser]anna16[/eluser]
by the way this is the output below,
http://coder9.com/ci/ztest.php/site/index


HTML Table class? - El Forum - 10-26-2010

[eluser]techgnome[/eluser]
I'm not sure what the problem is with it... the first array contains the column headers... Name, Color and Size...
The next three arrays contain the data for each column. This should all be explained in the user guide for the table functions... is it not?

-tg


HTML Table class? - El Forum - 10-26-2010

[eluser]gyo[/eluser]
Can you post your 'site.php' controller?
It looks like you're echoing something which creates the "headers already sent" PHP error.


HTML Table class? - El Forum - 10-26-2010

[eluser]anna16[/eluser]
http://coder9.com/ci/ztest.php/site/sample1/

here,
Code:
<?php

class Site extends Controller
{
    function __construct()
    {
        parent::Controller();
        $this->sample1();
    }

    function sample1() {
        $this->load->library('table');

        $data = array(
                     array('Name', 'Color', 'Size'),
                     array('Fred', 'Blue', 'Small'),
                     array('Mary', 'Red', 'Large'),
                     array('John', 'Green', 'Medium')
                     );

        echo $this->table->generate($data);
    }
    
    /*
    function sample2() {
        $this->load->library('table');

        $this->table->set_heading('Name', 'Color', 'Size');

        $this->table->add_row('Fred', 'Blue', 'Small');
        $this->table->add_row('Mary', 'Red', 'Large');
        $this->table->add_row('John', 'Green', 'Medium');

        echo $this->table->generate();
    }
    */
    
}
// end of site class



HTML Table class? - El Forum - 10-26-2010

[eluser]InsiteFX[/eluser]
Code:
$data = array (
    'table_open'          => '<table border="0" cellpadding="4" cellspacing="0">',

    '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 class="alt">',
    'row_alt_end'         => '</tr>',
    'cell_alt_start'      => '<td>',
    'cell_alt_end'        => '</td>',

    'table_close'         => '</table>'
);

InsiteFX


HTML Table class? - El Forum - 10-26-2010

[eluser]anna16[/eluser]
@InsiteFX

Thanks but i don't understand.
How do i use your codes to fix it,can you explain please.
Sorry I"m noob.


HTML Table class? - El Forum - 10-26-2010

[eluser]tonanbarbarian[/eluser]
take $this->sample1(); out of the constructor
that is resulting in the table being generated at least twice

[code] function __construct()
{
parent::Controller();
}[/code[


HTML Table class? - El Forum - 10-26-2010

[eluser]anna16[/eluser]
@tonanbarbarian

Thanks i remove it and it is working now fine.
By the way can you explain why when i insert this code below,

Code:
$this->sample1();

inside the constructor why it iterate the output 3 times.

Thanks in advanced.


HTML Table class? - El Forum - 10-26-2010

[eluser]anna16[/eluser]
@InsiteFX

I like you table codes,
can you teach me how do i incorporate your table codes with the output data?

Thanks again in advanced.