As per link in table?

2
I have a Table in PHP and in every tr I need a link
<?php
$con = mysqli_connect("localhost","root","", "saber");
mysqli_set_charset($con,"utf8");
$result = mysqli_query($con,"select id,nome,vista from mensagens");

while($row = mysqli_fetch_array($result)){
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td width = '86%'>" . $row['nome'] . "</td>";
    if($row['vista'] == 1)
        echo "<td>Sim</td>";
    else
        echo "<td>Não</td>";
    echo "</tr>";
}
?>  

Does anyone know how I do it?

    
asked by anonymous 10.07.2015 / 17:19

4 answers

1

I think this solves in the case of three:


echo '<tr style="cursor:pointer" onclick="location.href=\''.$link.'\'">';
    
10.07.2015 / 19:31
3

You can insert the link within <td>

while($row = mysqli_fetch_array($result)){
echo "<tr><a href=".$row['link'];
echo "<td>" . $row['id'] . "</td>";
echo "<td width = '86%'>" . $row['nome'] . "</td>";
if($row['vista'] == 1)
    echo "<td>Sim</td>";
else
    echo "<td>Não</td>";
echo "</tr></a>";
}

EDIT:

To make every tr have a link you can use javascript:

while($row = mysqli_fetch_array($result)){
echo "<tr onclick='location.href=.$row['link']."\'";
echo "<td>" . $row['id'] . "</td>";
echo "<td width = '86%'>" . $row['nome'] . "</td>";
if($row['vista'] == 1)
    echo "<td>Sim</td>";
else
    echo "<td>Não</td>";
echo "</tr>";
}
    
10.07.2015 / 17:22
1

The link can not be outside the Td. It has to stay inside the TD. Involving only text.

echo "<td><a href='".$link."'>" . $row['id'] . "</a></td>";
    
10.07.2015 / 17:29
0

You'll have to put a href around the <td>

echo "<a href=\"link\"><td>" . $row['id'] . "</td></a>";
    
10.07.2015 / 17:23