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> 

Since I don't have the database the only thing that I thought of is if a file is found in lines 2 to 10 that does not exist in your database, what happens?

I don't see that $link has been set (line 13). In any case, the error means you are processing 0 entries at line 23.