dtf1111 2016-03-21 23:48
浏览 36
已采纳

使用mysql和php创建映像文件夹的路径

Basically I have to create a jukebox type chart via mysql and php using xampp.

I've done the basics of setting up the table my referring to mysql database etc. I just dont get how to code the path to the image folder I have created.

My Image folder is in htdocs under my folder I created called Jukebox.

This is my code:

<!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?

  • 写回答

3条回答 默认 最新

  • dqq9695 2016-03-22 00:02
    关注

    I'm assuming you want the image in the "Albumcover" part of your code. If so you can echo out a html line. You can name your images in the "jukebox" folder with the album name. The code will appear as

     <td>" . $row["Artist"]. "</td>
     <td>" . $row["Title"]. "</td>
     <td>" . $row["Album"]. "</td>
     <td>" <img src=\"jukebox/".$row["Album"].".png\" >"</td>
    

    For that all images will need to be of file type png which is easy to do, just save them normally and add .png at the end. The same album name on your database will need to be the same name given to the file. There are other filetypes you can use such as .jpg.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀