How to pass a text from the database to display as a link on a site

0

Hello, I'm making a website in php and html, linked to a database in mysql.

And I have a news table in the database, with the idartigos, title, text and link fields.

The link is passing in text and I would like it when someone sees the news on the site, it becomes a link, so that the person clicks. Can someone help me?

 $query = mysqli_query($mysqli, "SELECT * FROM artigos WHERE activo = 1 ORDER BY idartigos DESC");
                                    while($row_artigos = mysqli_fetch_array($query))
                                    {                       
                                echo "<br><br>";
                                echo($row_artigos[1]);
                                echo "<br>";
                                echo($row_artigos[2]);
            # tirar # qdo tiver link        echo($row_artigos[3]);          

                                echo "<br><br>";
    
asked by anonymous 27.06.2017 / 21:57

4 answers

1

You must use the <a> tag and assign the $row_artigos[3] value to the href attribute.

Example:

echo '<a href="'.$link.'">'.$row_artigos[3].'</a>';

Edited:

$link = $row_artigos[3];
if (strpos($link,'http') === false)
  $link = 'http://'.$link;

echo '<a href="'.$link.'">'.$row_artigos[3].'</a>';
    
27.06.2017 / 22:18
0

I think you're looking to implement a common link on your page ...

Here is an example implementation: Link implementation example

What you want to display as a link will always be inserted inside the ' <a> ' tag, perform a search of the use of this tag that you can apply more effectively.

    
27.06.2017 / 22:02
0

Do you want the title to become a link? If so, you can do this:

echo "<a href='".$link."'>".$titulo."</a>";

Could not understand the question right, can you be clearer?

    
27.06.2017 / 22:03
0

For the text displayed to be the contents of column 1, and the link, the contents of column 3:

   echo("<a href='".$row_artigos[3]."'>".$row_artigos[1]."</a>");

For text and link to be from the same column:

echo("<a href='".$row_artigos[3]."'>".$row_artigos[3]."</a>");
    
27.06.2017 / 22:04