How to link to table?

Asked

Viewed 306 times

2

I have a Table in PHP and in each 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?

4 answers

3

You can insert the link inside the <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>";
}
  • Hello Ricardo I cheated when I said it was all td, was all tr, ie when you click a Row goes to another link

  • @Brunogibellino Editei, test ai.

  • It didn’t work on tr but it worked on a td I tested. But I can’t get the link to work on tr

  • of me more information will be placed only one link or will be placed one link in each Row (tr)?

  • in each tr will have a link

  • @Brunogibellino Editei.

Show 1 more comment

1


I believe this solves in the case of three:


echo '<tr style="cursor:pointer" onclick="location.href=\''.$link.'\'">';

1

The link cannot be left out of Td. it has to be inside td. Involving only the text.

echo "<td><a href='".$link."'>" . $row['id'] . "</a></td>";
  • Good Luke I made a mistake when elaborating the question I meant in all tr’s

0

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

echo "<a href=\"link\"><td>" . $row['id'] . "</td></a>";
  • 1

    href must be inside the td, not outside, or your HTML will be invalid

  • nuussssaa.......

Browser other questions tagged

You are not signed in. Login or sign up in order to post.