简体   繁体   中英

How can I output my URL row as a hyperlink (PHP)?

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. **Please do not offer comments on unrelated items, such as how to create an HTML link or output a single link as a hardcoded hyperlink. That's not what I'm asking. Also, to receive positive feedback and be considered an answer, I'd like someone to take the third line below and provide a demo. Thank you!

<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>

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM