Welcome Guest, Not a member yet? Register   Sign In
Insert a hyperlink inside a HTML Table Class
#1

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

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

[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().
#4

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

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

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

[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




Theme © iAndrew 2016 - Forum software by © MyBB