将时间与sql行关联

a5g8bdjr  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(381)

我有一些歌曲被存储在行中,我想创建一个带有时间戳的播放列表来显示歌曲播放的时间。我有艺术家/歌曲填充刚刚好,但时间只是显示当前时间。

$sql = "SELECT artist, title, starttime FROM radio_playlist_history WHERE name LIKE 'kbac' AND starttime LIKE '$starttime%' ORDER BY starttime DESC";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
 $time = end(explode(' ', $row["starttime"]));
 while($row = $result->fetch_assoc()) {
  print_r( "<div class='col-sm-6'><h4>Artist: " . $row["artist"]. " <br> Title: " . $row["title"]. "<br>". $time ."</h4></div>");
 }
 } else {
  print_r ("0 results");
 }


我可能错过了一些愚蠢的事情。任何帮助我都会感激的。

woobm2wo

woobm2wo1#

你能试试这个吗?请在循环中输入以下代码行。

$time = end(explode(' ', $row["starttime"]));

最终代码:

$sql = "SELECT artist, title, starttime FROM radio_playlist_history WHERE name LIKE 'kbac' AND starttime LIKE '$starttime%' ORDER BY starttime DESC";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row     
    while ($row = $result->fetch_assoc()) {
        $time = end(explode(' ', $row["starttime"]));
        print_r("<div class='col-sm-6'><h4>Artist: " . $row["artist"] . " <br> Title: " . $row["title"] . "<br>" . $time . "</h4></div>");
    }
} else {
    print_r("0 results");
}

相关问题