Skip to Content
It is currently October 6th, 2022, 5:37 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 14 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: 174
Location: Vancouver, BC, Canada
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: 10572
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: 174
Location: Vancouver, BC, Canada
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: 8306
Location: Cologne (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: 10572
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: 174
Location: Vancouver, BC, Canada
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: 10572
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  
 Post subject: Re: Date Last Played?
PostPosted: August 1st, 2022, 12:30 am 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 174
Location: Vancouver, BC, Canada
I've got this currently on my homepage:

Code:
<td align="center">
<p><?php if ( $now_playing["count_played"] > 0 ) { ?>
<?php echo( date( $configuration->date_time_format, strtotime( $last_played["date_played"] ) ) ); ?>
<?php } ?>
<?php if ( $now_playing["count_played"] = 0 ) { ?>
<?php echo "Never"; ?>
<?php } ?>
</td>


But I'm not sure from the query entered above where to (or what file) I put in the SQL to query the database and how to format it. I can see Never if the value is 0, but can't see a date because it doesn't have the SQL to drive the query. I think this will remain blank until the PHP knows where to find the data. When I put it in my code my page has a problem and won't load.

Would this be close to what I'm looking for? It breaks my PHP code every time no matter what .php file I put it into, but leaning toward class.song.php:

Code:
   public static function lastPlayed() {
      $db = Database::getInstance();
      $select = $db->select()
         ->from(array('h' => 'historylist'),
               array('*'))
         ->where('s.songtype = ?', 'S')
         ->order('h.date_played DESC')
         ->limit('HISTORY_COUNT+1')
      }
   return $last_played;
   }


Lord help me, I'm just not that proficient with PHP and mysqli queries.

_________________
Park Magic Radio
http://parkmagicradio.ca


Top
 Profile  
Reply with quote  
 Post subject: Re: Date Last Played?
PostPosted: August 9th, 2022, 6:11 am 
Offline
New User
New User

Joined: February 22nd, 2019, 1:20 pm
Posts: 24
I have read the whole post and I still do not understand where exactly you want to have placed the last date played info. I took a look into your website: Do you want to add last played info into "Recently Played" section ? or somewhere ?
Find attached a screenshot with my current played info and history - as example. I didn't use SAM page templates, the page is my own creation - but all the information displayed is used and generated with SAM tools available. My page is created as html and not php. But I think there is no difference in SAM html / php output reference. I may be corrected if I'm wrong.


Attachments:
bod history.jpg
bod history.jpg [ 49.22 KiB | Viewed 579 times ]
Top
 Profile  
Reply with quote  
 Post subject: Re: Date Last Played?
PostPosted: August 10th, 2022, 8:25 pm 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 174
Location: Vancouver, BC, Canada
Hello rolandwelker, thanks for your reply. Yes, you are exactly right, I wish to display the last date and time a song played in my "Currently Playing" section adjacent to the album art, alongside all the other info displayed. How did you accomplish this?

_________________
Park Magic Radio
http://parkmagicradio.ca


Top
 Profile  
Reply with quote  
 Post subject: Re: Date Last Played?
PostPosted: August 11th, 2022, 1:42 pm 
Offline
New User
New User

Joined: February 22nd, 2019, 1:20 pm
Posts: 24
Hi dan40, as I wrote before - I am using html output tools from SAM (Not using SAM php templates). All those info in my screenshot, last played, Info generated etc. have been generated from SAM by using the tag types and variables in SAM "Help" section, => html output section, => html output, =>Overview. As I am not familiar the way you create your output it may differ from php page generation. Initially I was in the same situation as you roughly 12 years ago, it was a mess to modify SAMs existing web templates, so I decided to create my web pages of my own using all that stuff from html output section which was much easier to create and to control. Find attached screenshots for more info. Find below objects inserted to create my history file as displayed in my pevious post:
<!--history.songtype="S"--> [Only displaying Song info - no jingles or whatever]
<!--LOOP(history,1,5)--> [Number of songs displayed]
<!--LOOP_ROW--> [Followed by Loop end]
$history.buycd$
$history.no$
$history.picture$
$history.artist$
$history.title$
$history.album$
$history.albumyear$
$history.date_played$

But as I wrote: I am not sure if these commands work within the php templates supplied with SAM. I am using those commands inside my own php or html templates created from SAM and uploaded to my my webspace.


Attachments:
variables.jpg
variables.jpg [ 106.93 KiB | Viewed 550 times ]
Top
 Profile  
Reply with quote  
 Post subject: Re: Date Last Played?
PostPosted: August 12th, 2022, 10:10 pm 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 174
Location: Vancouver, BC, Canada
I think the php equivalent of this would be:

Code:
<?php echo $currentSong->date_played; ?>


But, that just returns the current date and time that the song is playing. If I could somehow pull the last played date from the historylist for the $currentSong, I'd have it made! But my skills just aren't strong enough to figure out how to do this.

_________________
Park Magic Radio
http://parkmagicradio.ca


Top
 Profile  
Reply with quote  
 Post subject: Re: Date Last Played?
PostPosted: August 12th, 2022, 10:57 pm 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 174
Location: Vancouver, BC, Canada
Well, this does not produce any errors, but it does not produce any results either.

Code:
SELECT
    `date_played`
FROM
    `historylist`
WHERE
    songID IN("$currentSong['songID']")
ORDER BY
    date_played
DESC
LIMIT 2 OFFSET 1


Maybe it's trying to read the last played date and there isn't one until after the song has played?

_________________
Park Magic Radio
http://parkmagicradio.ca


Top
 Profile  
Reply with quote  
 Post subject: Re: Date Last Played?
PostPosted: August 13th, 2022, 12:21 pm 
Offline
New User
New User

Joined: February 22nd, 2019, 1:20 pm
Posts: 24
Yeah, I think the magic ist the word "history": => history.date_played <=, as everything regarding history like "history.artist" etc. (View my listing in my post above). You can find additional info at the buttom of the help section from SAM how to use.


Attachments:
help_02.jpg
help_02.jpg [ 213.49 KiB | Viewed 533 times ]
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 8 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