本文介绍了PHP中的Undefine索引错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为download_manager的表。它有两列文件名和下载。我想要做的是获取文件名及其下载次数,并将它们显示在ul元素内。
我能够获取文件名但我无法显示下载次数我得到了未定义的索引错误。这是我的代码
我尝试过:
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
What I have tried:
<?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>
推荐答案
这篇关于PHP中的Undefine索引错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!