Growing a list of links from a query
I have the following code which will extract the filename from the table and link to it. I want to do this, so I can later reference $ filesList and it will contain one block of html code with links to as many files as there are files.
I thought that adding to the previous variable would be the easiest way to do this, but it actually outputs pointless code: 0test.sh">test.sh
if ($getFiles = $con->prepare($filesQuery)) {
$getFiles->bind_param("s", $pk);
$getFiles->execute();
$getFiles->bind_result($FILENAME);
$files = array();
while ($getFiles->fetch()) {
$filename = array(
'FILENAME' => $FILENAME,
);
$files[] = $filename;
}
}
$filesList = '';
foreach ($files as $filenames)
{
$filesList = $filesList + '<p><a href="./files/'. $filenames['FILENAME'] .'">'. $filenames['FILENAME'] .'</a>' . "\n";
};
Sureley I don't need to have an array for what I want to do?
0
source to share
3 answers
Have you tried something like this? (Unverified code as I am not at home)
if ($getFiles = $con->prepare($filesQuery)) {
$getFiles->bind_param("s", $pk);
$getFiles->execute();
$getFiles->bind_result($FILENAME);
$files = array();
while ($getFiles->fetch()) {
$filesList = $filesList + '<p><a href="./files/'. $FILENAME .'">'. $FILENAME .'</a>' . "\n";
}
-1
source to share