php - 如何使用 php 和 mysql 上传图像文件夹

标签 php mysql sql xampp

基本上我必须使用 xampp 通过 mysql 和 php 创建一个点唱机类型图表。 我已经完成了引用 mysql 数据库等设置表的基础知识。我只是不知道如何编写我创建的图像文件夹的路径。我的图像文件夹位于我创建的名为 Jukebox 的文件夹下的 htdocs 中。这是我的编码:

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
     border: 1px solid black;
}
</style>
</head>
<body>

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "jukebox";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT * FROM Music";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
     echo "<table>

     <tr>

     <th>Artist</th>
     <th>Title</th>
     <th>Album</th>
     <th>Albumcover</th>
     <th>Play</th>
     </tr>";


// output data of each row
     while($row = $result->fetch_assoc()) {

         echo 

         "<tr>

         <td>" . $row["Artist"]. "</td>
         <td>" . $row["Title"]. "</td>
         <td>" . $row["Album"]. "</td>
         <td>" . $row["Albumcover"] 
         . "</td>
         <td>" . $row["Play"] . "</td>

         </tr>";
     }
     echo "</table>";

} else {
     echo "0 results";
} ?>         
</body>
</html>

This is what my php coding looks like

This is my image folder which i wish to create a path to so that all the album art can come up in the albumcover column

如何使用 php 和 mysql 创建此路径

最佳答案

<style>
.preview
{
    width:400px;
    border:solid 1px #dedede;
    padding:10px;
    color:#cc0000;

}
</style>
<?php
 // output data of each row
 while($row = $result->fetch_assoc()) {

     echo 

     "<tr>

     <td>" . $row["Artist"]. "</td>
     <td>" . $row["Title"]. "</td>
     <td>" . $row["Album"]. "</td>
     <td><img class='preview' src='jukebox/img/" . $row["Albumcover"] ."' alt=".$row["Albumcover"]."></td>
     <td>" . $row["Play"] . "</td>

     </tr>";
 }

关于php - 如何使用 php 和 mysql 上传图像文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36145068/

相关文章:

sql - 对一列进行分组并获取该列的总和

php - 用户名已被使用

mysql - SELF JOIN 唯一结果集问题 - MySQL

我的 cron 脚本 sourcebans.php 中出现 mysql_fetch 错误

c# - 多线程数据库插入

sql - 如何列出 postgres 模式中的关系

php - 使用 Condition 子句查询两个表中选定的列

php - 从 PHP 执行程序挂起 APACHE

php - JSON无法通过php正确插入到mysql中

php - 使用 htmlentities 保留换行符?