douwei8911 2016-03-22 02:14
浏览 35
已采纳

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

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 don't 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 coding:

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

How do I create this path with php and mysql

  • 写回答

2条回答 默认 最新

  • douzi2785 2016-03-22 02:54
    关注
    <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>";
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器