我尝试从我的数据库中读取数据,但我不知道它不起作用并向我显示该错误
注意:第65行的C:\ Users \ VladxD \ Desktop \ Xampp \ htdocs \ Web(工作空间)\ Test \ show_animation.php中的数组到字符串转换
这是我的代码:
的mysql_connect:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpassword = '';
$conn = mysqli_connect($dbhost, $dbuser, $dbpassword, "portofoliu_database") or die ("<div id='err'>Could not connect:</div> ");
代码:
<?php session_start(); ?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Directory Contents</title>
<link rel="stylesheet" href="show_folder.css">
<link rel="stylesheet" href="NewFile.css">
</head>
<body>
<div id=wapper>
<?php include 'Menu.php';
include 'MySQL_connect.php'; ?>
<div class="box">
<div id="container">
<table class="sortable">
<thead>
<tr>
<th>File name</th>
<th>Uplaod time</th>
</tr>
</thead>
<tbody>
<?php
// Opens directory
$user = @$_SESSION ['account'];
$dir = @$_SESSION ['account'] . '/image/';
if (is_dir($dir) == true) {
$myDirectory = opendir($dir);
// Gets each entry
while ($entryName = readdir($myDirectory)) {
$dirArray [] = $entryName;
}
// Closes directory
closedir($myDirectory);
// Counts elements in array
$indexCount = count($dirArray);
// Sorts files
sort($dirArray);
// Loops through the array of files
for ($index = 0; $index < $indexCount; $index++) {
// Allows ./?hidden to show hidden files
if ($_SERVER ['QUERY_STRING'] == "hidden") {
$hide = "";
} else {
$hide = ".";
}
//-------------------------------------------------------------------------------------------------
//$modtime=date("M j Y g:i A", filemtime($dir.$dirArray[$index]));
$modtime_test = mysqli_query($conn, "SELECT file_upload_time FROM users WHERE file_name ='$dirArray[$index]'");
$modtime = mysqli_fetch_assoc($modtime_test);
$timekey = date("YmdHis", filemtime($dir . $dirArray[$index]));
//-------------------------------------------------------------------------------------------------
if (substr($dirArray [$index], 0, 1) != $hide) {
// Gets File Names
$name = $dirArray [$index];
// Print 'em
echo "
<tr class='file'>
<td><a href=#' onclick='showImage(\"$index\")'>$name</a></td>
<td sorttable_customkey='$timekey'><a href='#'>$modtime</a></td>
</tr>";
}
}
}
?>
</tbody>
</table>
</div>
<div id="imageHolder">
<?php if (is_dir($dir) == false)
echo("<div id = 'noFile'>Your folder it's empty, upload file</div>");
?>
<script>
var array = [
<?php
foreach ($dirArray as $item)
{
echo "\"$dir{$item}\",";
}
?>
];
function showImage(index) {
var url = array[index];
url = "<img src='" + url + "'>";
document.getElementById("imageHolder").innerHTML = url;
}
</script>
</div>
</div>
</div>
</body>
</html>
我想从我的数据库中获取数据并在我的文件夹中显示
这是我在数据库中的元素:http://i.imgur.com/kYciFQJ.png
这是我的网站:http://i.imgur.com/HeEv1yG.png 如果您在下面看到&#34;上传时间&#34;我有这个文字&#34;数组&#34;但我希望从我的数据库中获取数据时间并放在那里。
答案 0 :(得分:0)
由于mysqli_fetch_assoc返回一个数组,而不是单个值,即使返回了一个字段...尝试更改
$modtime = mysqli_fetch_assoc($modtime_test);
到
$results = mysqli_fetch_assoc($modtime_test);
$modtime = $results["file_upload_time"];
答案 1 :(得分:0)
您有PHP通知,“PHP数组到字符串转换”。
<tr class='file'>
<td><a href=#' onclick='showImage(\"$index\")'>$name</a></td>
<td sorttable_customkey='$timekey'><a href='#'>$modtime</a></td>
</tr>";
代码中$modtime
是数组。您需要使用$modtime['file_upload_time']
。