I have a table called download_manager .It has two columns filename and downloads .What I want to do is to get file name and its download count and display them inside ul element.
I am able to get file names but I cant display the download count I'm getting undefined index error.This is my code
<?php
$handle = opendir($directory) or die('Error');
$files = array();
while ($file = readdir($handle)) {
if ($file[0] == '.') {
continue;
}
$files[] = $file;
}
sort($files, SORT_STRING);
$query = 'select * from download_manager';
$data = mysqli_query($link, $query);
$fileInfo[] = array();
if (mysqli_num_rows($data)) {
while ($singleFile = mysqli_fetch_array($data)) {
$fileInfo[$singleFile['filename']] = $singleFile['downloads'];
}
}
?> <!DOCTYPE html> <html> <head> </head> <body> <ul> <?php
foreach ($files as $key => $value) {
echo '<li><a href="download.php?file='.urlencode($value).'">'.$value.'</a> <span>'.$fileInfo[$value].'</span> ';
}
?> </ul> </body> </html>