使用 mysql 和 php 创建图像文件夹的路径
Create a path to image folder using mysql and php
基本上我必须通过 mysql 和 php 使用 xampp 创建点唱机类型的图表。
我已经完成了设置 table 我指的 mysql 数据库等的基础知识。我只是不知道如何编写我创建的图像文件夹的路径。
我的 Image
文件夹位于 htdocs
我创建的名为 Jukebox 的文件夹下。
这是我的代码:
<!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 comes up as my online jukebox, and in the Album cover column I want the album art to come up
And this is where my images are, how would i create the path to img folder so the album art comes up?
我假设您想要代码的 "Albumcover" 部分中的图像。如果是这样,您可以回显 html 行。您可以使用相册名称为 "jukebox" 文件夹中的图像命名。该代码将显示为
<td>" . $row["Artist"]. "</td>
<td>" . $row["Title"]. "</td>
<td>" . $row["Album"]. "</td>
<td>" <img src=\"jukebox/".$row["Album"].".png\" >"</td>
为此,所有图像都需要是 png 文件类型,这很容易做到,只需正常保存并在末尾添加 .png 即可。数据库中的相同专辑名称需要与文件的名称相同。您还可以使用其他文件类型,例如 .jpg。
我真的不明白你的问题。
您在 "albumcover" 中存储了什么?
假设您将相对路径保存到相册封面。
所以你可以打印出来
<td><img src="' . $row["Albumcover"] . '"></td>
使用你的 mp3 作为标签并在新的 tab.May 中打开它 needed.I 假定 jukebox/mp3/ 作为你的 mp3 文件夹
<?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 src='jukebox/img/" . $row["Albumcover"] ."' alt=".$row["Albumcover"]."></td>
<td><a href='jukebox/mp3/" . $row["Play"] . "' target='blank'>" . $row["Play"] . "</a>
</td>
</tr>";
}
基本上我必须通过 mysql 和 php 使用 xampp 创建点唱机类型的图表。
我已经完成了设置 table 我指的 mysql 数据库等的基础知识。我只是不知道如何编写我创建的图像文件夹的路径。
我的 Image
文件夹位于 htdocs
我创建的名为 Jukebox 的文件夹下。
这是我的代码:
<!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 comes up as my online jukebox, and in the Album cover column I want the album art to come up
And this is where my images are, how would i create the path to img folder so the album art comes up?
我假设您想要代码的 "Albumcover" 部分中的图像。如果是这样,您可以回显 html 行。您可以使用相册名称为 "jukebox" 文件夹中的图像命名。该代码将显示为
<td>" . $row["Artist"]. "</td>
<td>" . $row["Title"]. "</td>
<td>" . $row["Album"]. "</td>
<td>" <img src=\"jukebox/".$row["Album"].".png\" >"</td>
为此,所有图像都需要是 png 文件类型,这很容易做到,只需正常保存并在末尾添加 .png 即可。数据库中的相同专辑名称需要与文件的名称相同。您还可以使用其他文件类型,例如 .jpg。
我真的不明白你的问题。 您在 "albumcover" 中存储了什么? 假设您将相对路径保存到相册封面。 所以你可以打印出来
<td><img src="' . $row["Albumcover"] . '"></td>
使用你的 mp3 作为标签并在新的 tab.May 中打开它 needed.I 假定 jukebox/mp3/ 作为你的 mp3 文件夹
<?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 src='jukebox/img/" . $row["Albumcover"] ."' alt=".$row["Albumcover"]."></td>
<td><a href='jukebox/mp3/" . $row["Play"] . "' target='blank'>" . $row["Play"] . "</a>
</td>
</tr>";
}