make rows link in php

0

Good Night, I have a database and in it two columns, one of Links and the other of names, these links are for pages with more information about the movie, and the column name contains the names of the movies, well, I want my site to list the movies by the names and these names are links to the pages, I've tried everything that my knowledge allows, which is very little, I hope they 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>');
    }
}
    
asked by anonymous 09.11.2016 / 00:18

1 answer

2

Something in this line:

$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 an array with the name of the fields.

We use htmlentities to hit special characters such as apostrophes / quotes, quotation marks, and more in HTML.

In addition, the address was put with urlencode in 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 () / a>

    
09.11.2016 / 00:21