0

I have been trying to use various combinations of anchor and html tags to code my third row as an actual URL (each time) instead of plain text, and it's not working. To be clear, I am not trying to hardcode a single URL and output as a hyperlink but rather attempting to code in such a way that this third row is consistently outputted as a clickable hyperlink. This is a .php page, and the links are .pdf URLs. I'm also finding this a little more difficult to do because it's a table (so, extra formatting there).

What I'm doing is retrieving many articles from my database, each with the third row as a URL, and then using the below code to output it in my webserver, using tags, with the php . as a separator, etc. However, I'm not able to output the row, which currently displays as plain text, as a set of clickable hyperlinks.

I'm not looking for how to HTML link or output a single link as a hardcoded hyperlink. That's not what I'm asking. I'd also like someone to take the third line below and provide a demo.

<table class="table" width="920" style="border:thin" cellpadding="10" border="1">
<tr>
<th>Topic</th>
<th>Category</th>
<th>URL</th>
</tr>

<?php
while($row = $result->fetch_assoc()){
    ?>
    <tr>
    <td><?php echo $row['Topic']; ?></td>
    <td><?php echo $row['Category']; ?></td>
    <td><?php echo $row['URL']; ?></td>
    </tr>
    <?php
    }
?>

</table>
Zoe
  • 27,060
  • 21
  • 118
  • 148
lorena
  • 386
  • 1
  • 2
  • 15
  • Does this answer your question? [How To Make HTML Links](https://stackoverflow.com/questions/22314781/how-to-make-html-links) – FluffyKitten Aug 29 '20 at 04:05
  • No it doesn't. Please re-read the question (or review the answer below, which does answer what I'm asking about). – lorena Aug 31 '20 at 18:05

2 Answers2

2

Your third line should be like this

<td><a href="<?php echo $row['URL']; ?>">  the link text </a></td>

if you need the link and text to be same the code will look like this

<td><a href="<?php echo $row['URL']; ?>"><?php echo $row['URL']; ?></a></td>

Basically, its like this

<td><a href=" ECHO URL HERE "> ECHO THE URL TEXT HERE </a></td>
kiranvj
  • 32,342
  • 7
  • 71
  • 76
1

In HTML you can create a link with an anchor tag <a>.

Please try this:

<td> 
  <a target="_blank" href="<?php echo $row['URL']; ?>"> <?php echo $row['URL']; ?></a> 
</td>
shinjw
  • 3,329
  • 3
  • 21
  • 42