Welcome Guest, Not a member yet? Register   Sign In
HTML Table class?
#1

[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.
#2

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

[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
#4

[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.
#5

[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
#6

[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
#7

[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.
#8

[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[
#9

[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.
#10

[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.




Theme © iAndrew 2016 - Forum software by © MyBB