make Rows link in php

Asked

Viewed 29 times

0

Good evening, I have a database and in it two columns, one of Links and the other of names, these links are to pages with more information about the film, and the column name contains the names of the films, well, I want my site to list the movies by their names and those names to be links to the pages, I’ve tried everything that my knowledge allows, which is very little, I hope you help me.

$query = "SELECT paginas, Nome FROM links_paginas_filmes";

$result = mysqli_query($link, $query);

while($row = mysqli_fetch_row($result)) {
    foreach($row as $field => $value) {
        if($field != 'paginas') continue;
        echo ('<a href="Black-Mirror.html">' . $value . '</a>');
    }
}

1 answer

2

Something along those lines:

$query = "SELECT paginas, Nome FROM links_paginas_filmes";
$result = mysqli_query($link, $query);

while($row = mysqli_fetch_row($result)) {
   echo '<a href="'.urlencode($row['paginas']).'">'.htmlentities($row['Nome']).'</a>';
}

The variable $row already returns a array with the name of the fields.

We use htmlentities to match special characters such as apostrophes/quotes, quotes and others in HTML.

In addition, the address was placed with urlencode in the href="" for similar reason. There are cases where you need this construction:

htmlentities(urlencode($row['paginas']));

Understand the difference in the PHP manual:

urlencode()
htmlentities()
htmlspecialchar()

  • No chance, man, nothing shows up :(

Browser other questions tagged

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