0
I have this php and html code that lists files from a folder, but I would like to put the results in a table, but for each row is being repeated the column title, Directoryiterator managed to solve, follows the updated code:
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<?php
$path = "arquivos/";
echo "<h2>Lista de Arquivos:</h2><br />";
foreach (new DirectoryIterator($path) as $fileInfo) {
if($fileInfo->isDot()) continue;
echo "<table>
<tr>
<th>Nome</th>
</tr>
<tr>
<td><a href='".$path.$fileInfo->getFilename() ."'>".$fileInfo->getFilename()."</a><br /></td>
</tr>
</table>";
}
?>
</body>
</html>
<?php
First, remove the
<tr>
which has the name of the repeat loop column if you do not want it to repeat itself; second, search onDirectoryIterator
of PHP.– Woss
Solved no! @Andersoncarloswoss
– Miguel Silva
@Andersoncarloswoss the Directoryiterator managed to understand and solved, but the column name keeps repeating
– Miguel Silva