Skip to Content
It is currently May 25th, 2020, 12:21 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Date Last Played?
PostPosted: September 25th, 2019, 10:47 am 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 134
Hi team, I saw a webpage using SAM/PHP that showed the last date a song was played.

In class.song.php I saw that there was this code:

Code:
public $date_played;


However, when I added it to display.playing.php, it shows me the current date and time, even if the track has been played more than once. I need it to display the last time it was played, not that it's being played right now.

How do I achieve this? Is there another variable in class.song.php I can add? Where can I get a list of the variables that are not listed in this file?

_________________
Park Magic Radio
http://parkmagicradio.ca


Top
 Profile  
Reply with quote  
 Post subject: Re: Date Last Played?
PostPosted: September 26th, 2019, 8:23 am 
Offline
SVS Member
SVS Member

Joined: May 8th, 2004, 9:00 am
Posts: 10488
Location: Denver, CO
Since you are displaying the currently playing song info, date_played is updated in the songlist table immediately upon playing, you will have to search the historylist (the song ID) table to get the last time it played before the current playing (offset the results by 1 to eliminate the current playing date).

_________________
- Rob Oyler, SVS
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Date Last Played?
PostPosted: March 3rd, 2020, 12:13 am 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 134
Hi DJ Cassio, I can get it to pull the date from the historylist's date_played table, but when I offset it with -1 as you suggest, it takes an entire year off the last played date. Here is my PHP:

Last Played: <?php echo $currentSong->date_played -date()-1; ?>

If it was played today on March 2, 2020, it would say "2019".

Any ideas?

_________________
Park Magic Radio
http://parkmagicradio.ca


Top
 Profile  
Reply with quote  
 Post subject: Re: Date Last Played?
PostPosted: March 3rd, 2020, 7:39 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7968
Location: Aachen (Germany)
Take a step back and reread the post by DJ Cassio.
There's no mentioning of offsetting the date_played field.

You take the songID from the current song, query the historylist for that song and pick the second to last entry (when ordered by date descending).

There is no field in the songlist table (or the latest historylist entry for that matter) telling you the second to last time a track has played.

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
 Post subject: Re: Date Last Played?
PostPosted: March 4th, 2020, 8:18 am 
Offline
SVS Member
SVS Member

Joined: May 8th, 2004, 9:00 am
Posts: 10488
Location: Denver, CO
Here is an example
Code:
SELECT date_played FROM historylist where songID in " . $now_playing["song_id"] . " Order by date_played DESC Limit 2 offset 1"
, you may need to adjust the song_id variable to match your query that gets the tracks.

_________________
- Rob Oyler, SVS
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Date Last Played?
PostPosted: March 4th, 2020, 10:16 pm 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 134
DJ Cassio wrote:
Here is an example
Code:
SELECT date_played FROM historylist where songID in ( " . $now_playing["song_id"] . " ) Order by date_played DESC Limit 2 offset 1"
, you may need to adjust the song_id variable to match your query that gets the tracks.


Thanks for the SQL query. the "songid" quoted above works only if I surround it in single quotes.

SELECT date_played FROM historylist where songID in ( " . $now_playing['songid'] . " ) Order by date_played DESC Limit 2 offset 1

How do I write it in php code?

_________________
Park Magic Radio
http://parkmagicradio.ca


Top
 Profile  
Reply with quote  
 Post subject: Re: Date Last Played?
PostPosted: March 5th, 2020, 7:47 am 
Offline
SVS Member
SVS Member

Joined: May 8th, 2004, 9:00 am
Posts: 10488
Location: Denver, CO
dan40 wrote:
How do I write it in php code?

I don't use the SAM templates, I use mysqli for my queries, however this is how I use the above query.


Code:
  //Select Date Last played
  $result = mysqli_query( $samDB, "SELECT date_played FROM historylist where songID in ( " . $now_playing["song_id"] . " ) Order by date_played DESC Limit 2 offset 1" );
  $last_played = mysqli_fetch_array( $result );

Code:

<?php if ( $now_playing["count_played"] > 1 ) { ?>
 <tr>
    <td align=right nowrap><b>Last Played:</b></td>
    <td>&nbsp;&nbsp;</td>
    <td align=left><?php echo( date( $configuration->date_time_format, strtotime( $last_played["date_played"] ) ) ); ?></td>
 </tr>
 <?php } ?>

_________________
- Rob Oyler, SVS
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group