简体   繁体   中英

Associate Time with SQL Row

I have songs that are being stored in rows and I wanted to create a playlist with a timestamp to show what time the song played. I have the artist/song populating just fine, but the time is just showing the current time.

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

在此处输入图像描述

Im probably missing something stupid. Any help I would appreciate it.

Could you try this? Please put the following code line in the loop.

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

Final code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM