Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyperlink across table cells?

I am trying to create a hyperlink from two pieces of text split over two cells in a table row.

I am generating my table using PHP to echo out the results from my database to a table. When it echo's it generates a hyperlink with GET variables at the end which allow the user to visit a page relevant to that information.

The problem is that I can't seem to generate a hyperlink that will go across those table cells, I have looked around the web and there is nothing that says I cannot do this.

As you can see from the screenshot below I am generating a hyperlink inside one table cell but I want the other table cell to have the same hyperlink.

enter image description here

Code

while ($row = $db->fetch_assoc($newest))
                        {
                            echo "<tr>";
                                echo "<td>";
                                    echo  "<a href='manager.php?method=view&id=".$row['id']."'>".$row['first_name']." ". $row['second_name']. "</td><td>".$row['company_name']."</a>";
                                echo "</td>";
                            echo "</tr>";
                        }

I have a feeling that I will just have to generate two separate hyperlinks for the table cells.

However I am hoping someone here can prove me wrong and save me a few lines of code.

Thanks :)

like image 296
tomaytotomato Avatar asked Dec 19 '25 23:12

tomaytotomato


2 Answers

Using native hyperlinks, you will have to create separate wrappers for each cell.

However, if you want to use JS for linking and redirecting, you could do something like:

.....
<tr class="clickable" data-href="http://google.com">
<td>cell-1</td>
<td>cell-2</td>
<td>cell-3</td>
</tr>
....

and then:

$(function(){
    $('tr.clickable').click(function(){
        window.location.href = $(this).attr('data-href');
    });
});
like image 115
Jovan Perovic Avatar answered Dec 21 '25 12:12

Jovan Perovic


Simply work around it with JS:

echo "<tr onclick=\"location.href='manager.php?method=view&id=".$info.";'\">";
like image 38
Eugen Rieck Avatar answered Dec 21 '25 14:12

Eugen Rieck