0

I'm trying to print in a table some rows and i want to print the variable .$row['web']. as a link.

The code is:

while($row = $sql_esp->fetch_array())
  {
    echo "<tr>";
    echo "<td style='border: 1px solid black;'>".$row['name']."</td>";
    echo "<td style='border: 1px solid black;'>".$row['place']."</td>";
    echo "<td style='border: 1px solid black;'>".$row['web']."</td>";
    echo "<td style='border: 1px solid black;'>".$row['email']."</td>";
    echo "<td style='border: 1px solid black;'>".$row['note']."</td>";
    echo "</tr></tbody</table>";
    }
    echo "</div>";

I tried to change this line:

echo "<td style='border: 1px solid black;'>".$row['web']."</td>";

in:

echo "<td style='border: 1px solid black;'><a href='".$row['web']."'></td>";

But it doesn't work. How can i fix?

5
  • And what's the link destination? Commented May 30, 2018 at 12:28
  • 2
    close your a like echo "<td style='border: 1px solid black;'><a href='".$row['web']."'>'.$row['web'].'</a></td>"; see documentation Commented May 30, 2018 at 12:28
  • 1
    </tbody</table> should be out of while loop Commented May 30, 2018 at 12:30
  • echo "<td style='border: 1px solid black;'><a href='".$row['web']."'>".$row['web']."</a></td>"; In this way works. Commented May 30, 2018 at 12:31
  • Also, you shouldn't echo HTML elements, you should print the HTML in plain HTML and then echo in the variables with PHP; E.G: <td style="border: 1px solid black;"><?=$row['name'];?></td> Commented May 30, 2018 at 12:38

1 Answer 1

4

<a> tag needs a text after and a closing </a> so:

echo "<td style='border: 1px solid black;'><a href='".$row['web']."'>".$row['web']."</a></td>";
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.