gpt4 book ai didi

PHP从数据库读取数据的问题

转载 作者:行者123 更新时间:2023-11-29 22:32:34 25 4
gpt4 key购买 nike

我尝试从数据库中读取数据,但我不知道它不起作用并显示该错误

Notice: Array to string conversion in C:\Users\VladxD\Desktop\Xampp\htdocs\Web(workspace)\Test\show_animation.php on line 65

这是我的代码:

MySQL_连接:

<?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如果您看到下面的“上传时间”,我有这个文本“数组”,但我想从数据库中获取数据时间并将其放在那里。

最佳答案

由于 mysqli_fetch_assoc 返回一个数组,而不是单个值,即使返回单个字段...尝试更改

$modtime = mysqli_fetch_assoc($modtime_test);

$results = mysqli_fetch_assoc($modtime_test);
$modtime = $results["file_upload_time"];

关于PHP从数据库读取数据的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29686298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com