CodeIgniter Forums
using table class to generate a hyperlink instead of a column - 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: using table class to generate a hyperlink instead of a column (/showthread.php?tid=36150)



using table class to generate a hyperlink instead of a column - El Forum - 11-23-2010

[eluser]heaversm[/eluser]
Hi - I am grabbing 4 fields from my database and generating a table - Client, Project, Role, and URL. The URL, however, I want to be a hyperlink for the Client column, instead of a column on its own. Currently, my code is this:

Code:
$this->db->select('clients.client, project_list.project, project_list.role, project_list.url');
        $this->db->from('clients, project_list');
        $where = "clients.id = project_list.client_id";
        $this->db->where($where);
        
        $query = $this->db->get();

        $this->table->set_heading('Client','Project','Role','URL');
        
        return $this->table->generate($query);

How do I modify it to accomplish that. If it can't be done, how do you manually build a table in CI?


using table class to generate a hyperlink instead of a column - El Forum - 11-23-2010

[eluser]skunkbad[/eluser]
[quote author="heaversm" date="1290549593"]Hi - I am grabbing 4 fields from my database and generating a table - Client, Project, Role, and URL. The URL, however, I want to be a hyperlink for the Client column, instead of a column on its own. Currently, my code is this:

Code:
$this->db->select('clients.client, project_list.project, project_list.role, project_list.url');
        $this->db->from('clients, project_list');
        $where = "clients.id = project_list.client_id";
        $this->db->where($where);
        
        $query = $this->db->get();

        $this->table->set_heading('Client','Project','Role','URL');
        
        return $this->table->generate($query);

How do I modify it to accomplish that. If it can't be done, how do you manually build a table in CI?[/quote]

You would want to loop through your query results, outputting tr's and td's as needed. TR for each row, TD for each field.


using table class to generate a hyperlink instead of a column - El Forum - 11-24-2010

[eluser]danmontgomery[/eluser]
Code:
foreach($query->result() as $row) {
    $this->table->add_row($row->client, $row->project, $row->role, anchor($row->url, $row->client));
}

return $this->table->generate();