将时间与 SQL 行关联

我有按行存储的歌曲,我想创建一个带有时间戳的播放列表以显示歌曲播放的时间。我的艺术家/歌曲填充得很好,但时间只是显示当前时间。


$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");

 }

https://img2.mukewang.com/64c5f6610001af0106470416.jpg

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



动漫人物
浏览 78回答 1
1回答

潇湘沐

你能试试这个吗?请将以下代码行放入循环中。$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) {&nbsp; &nbsp; // output data of each row&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; while ($row = $result->fetch_assoc()) {&nbsp; &nbsp; &nbsp; &nbsp; $time = end(explode(' ', $row["starttime"]));&nbsp; &nbsp; &nbsp; &nbsp; print_r("<div class='col-sm-6'><h4>Artist: " . $row["artist"] . " <br> Title: " . $row["title"] . "<br>" . $time . "</h4></div>");&nbsp; &nbsp; }} else {&nbsp; &nbsp; print_r("0 results");}
打开App,查看更多内容
随时随地看视频慕课网APP