CodeIgniter Forums
Insert a hyperlink inside a 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: Insert a hyperlink inside a HTML Table Class (/showthread.php?tid=16400)



Insert a hyperlink inside a HTML Table Class - El Forum - 03-05-2009

[eluser]Slowcheetah[/eluser]
How can i insert a link inside a HTML Table Class? This is my current code.

Code:
function competitie_top_5()
    {
        $this->db->select('username, rating');

        $query = $this->db->get('users_ratings'), 5);
        
        return $this->table->generate($query);
    }

And i want to have the username to be an hyperlink. For example;

Code:
<a href='profiles/$username'>$username</a>



Insert a hyperlink inside a HTML Table Class - El Forum - 03-05-2009

[eluser]jedd[/eluser]
I'm probably missing the subtlety of the question, but is anchor() your friend, combined with some table->add_row() magic?

More information at : [url="http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html"]http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html[/url]

[url="http://ellislab.com/codeigniter/user-guide/libraries/table.html"]http://ellislab.com/codeigniter/user-guide/libraries/table.html[/url]


Insert a hyperlink inside a HTML Table Class - El Forum - 03-05-2009

[eluser]Slowcheetah[/eluser]
Okay, anchor() is to actualy generate the link.

But how to insert this link in a existing cell from the generated table? So not a newly added with add_row().


Insert a hyperlink inside a HTML Table Class - El Forum - 03-05-2009

[eluser]jedd[/eluser]
[quote author="Slowcheetah" date="1236303601"]
But how to insert this link in a particular cell from the generated table? (not a newly added)[/quote]

Ah, yes, I realised my mistake and was editing my earlier response. You were too fast!

AFAIK you are going to have to 'manually' do the add_row stuff, and insert your own anchor'd links as you go.


Insert a hyperlink inside a HTML Table Class - El Forum - 03-05-2009

[eluser]kgill[/eluser]
You can't, as far as I know the table class doesn't have any options for modifying the data that is put into the cells. You either have to build the table yourself or modify the array you're sending it. Since it looks like you're only dealing with 5 rows you could use PHP's array_walk to add the anchor tags to your array via a callback function.


Insert a hyperlink inside a HTML Table Class - El Forum - 03-05-2009

[eluser]TheFuzzy0ne[/eluser]
Alternatively, you should be able to use CONCAT in your database query.


Insert a hyperlink inside a HTML Table Class - El Forum - 04-24-2009

[eluser]seanloving[/eluser]
This is what I came up with to hyperlink specific cell values as the table is generated.

Code:
foreach($active->result_array() as $row)
{
   $row['rental_order_id']=anchor('rentals/active/'.$row['rental_order_id'],$row['rental_order_id']);
   $this->table->add_row($row);
}
echo $this->table->generate();

SL