CodeIgniter Forums

Full Version: table class remove ID field when displaying the table
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]R_Nelson[/eluser]
i have a DB that stores my karaoke songs it has ID,SONG_NAME,ARTIST

all i want to do for the moment is when i display it is remove the ID so all i have is song name and artist i'm amusing this can be done via a template from what i read about the table class how do i set up a template?

El Forum

[eluser]R_Nelson[/eluser]
i have done quite a few searches on the net for this information and it looks like i would just have to make my table my self instead of using the table library

El Forum

[eluser]cahva[/eluser]
If you want to view the table without and id, you can. Just select the fields you want and pass it to the table generate function:
Code:
$q = $this->db->select('SONG_NAME,ARTIST')->get('songs');

$this->table->set_heading('Song name','Artist');
echo $this->table->generate($q);

I myself havent used html table class in years. I prefer the freedom to define the table how I want(of course you can define it via templates in the table class but imho its easier to just pass the results to the view and modify the looks in that).

El Forum

[eluser]InsiteFX[/eluser]
Hi R_Nelson

First you wil need a MY_Controller makes it easier to use the the Table Class!

MY_Controller - application/core/MY_Controller
Code:
class MY_Controller extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
    
        $this->load->library('table');

        $tmpl = array (
            'table_open'         => '<table border="0" cellpadding="4" cellspacing="0">',

            'thead_open'         => '<thead>',
            'thead_close'        => '</thead>',

            'heading_row_start'  => '<tr>',
            'heading_row_end'    => '</tr>',
            'heading_cell_start' => '<th>',
            'heading_cell_end'   => '</th>',

            'tbody_open'         => '<tbody>',
            'tbody_close'        => '</tbody>',

            '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>'
        );

        $this->table->set_template($tmpl);
    }
}

Controller extended for the above MY_Controller
Code:
public function index()
    {
        // Setting headings for the table
        $this->table->set_heading('ID', 'Song', ,'Artisit', 'Actions');

        // $data will be what you pull from your database table!
        foreach ($data as $value => $key)
        {
            // Build actions links for editing and deleting records! you can do away with this part if your do not need it
            $actions = anchor("link_to_edit/edit/".$key['id']."/", "Edit") . anchor("link_to_delete/delete/".$key['id']."/", "Delete");

            // Adding a new row to table, remove any $key you do not need.
            $this->table->add_row($key['id'], $key['song'], $key['artisit'], $actions);
        }
    }

View
Code:
&lt;!-- Generate the table in the view. --&gt;
&lt;?php echo $this->table->generate();?&gt;

Note: If you need to redo the table $this->table->clear();

InsiteFX

El Forum

[eluser]R_Nelson[/eluser]
ok thats not what i was looking for i just dont want it to show the ID coloum!

El Forum

[eluser]InsiteFX[/eluser]
If you do not want it to show just remove the $key['id']

InsiteFX

El Forum

[eluser]R_Nelson[/eluser]
so just building the table manually is my best bet since i have no idea how to remove it using the table library?

El Forum

[eluser]R_Nelson[/eluser]
Quote:If you want to view the table without and id, you can. Just select the fields you want and pass it to the table generate function:
$q = $this->db->select('SONG_NAME,ARTIST')->get('songs');

$this->table->set_heading('Song name','Artist');
echo $this->table->generate($q);

I myself havent used html table class in years. I prefer the freedom to define the table how I want(of course you can define it via templates in the table class but imho its easier to just pass the results to the view and modify the looks in that).

lol this is what i get for only reading the last message i guess my question was already answered! i just missed it!