Weekly schedule help

Post January 7th, 2006, 12:55 am

I have no idea how to do this so I'm going to need plenty of help to point me in the right direction.

I want to upload several audio files to my website, I will have all the audio info stored in a mysql table. I will have the entries numbered (say 1-50) which I have no problem making, but then the hard part.

I want a script that will automatically play the correct entry number based on what week it is. Say this Sunday will start week 1, so play audio file 1, then every week it will automatically play the next file in series until it reaches the end of the list it will start at file 1 again.


how possible is this?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post January 7th, 2006, 12:55 am

  • Vincent
  • Expert
  • Expert
  • User avatar
  • Joined: Dec 01, 2005
  • Posts: 722
  • Loc: Brisbane, Australia
  • Status: Offline

Post January 7th, 2006, 2:27 am

Try this

Code: [ Download ] [ Select ]
$date = date("W");
if(file_exists("audio/$date.mp3")) {
 echo "<embed src='audio/$date.mp3' loop='true'>";
} else {
 echo "Sorry, there is no music for this week";
}
  1. $date = date("W");
  2. if(file_exists("audio/$date.mp3")) {
  3.  echo "<embed src='audio/$date.mp3' loop='true'>";
  4. } else {
  5.  echo "Sorry, there is no music for this week";
  6. }

The only things to consider is that the first 9 files would need to have a zero infront of them (eg. 01.mp3, 02.mp3) and the 'week' starts on a monday

Post January 7th, 2006, 2:31 am

I honestly didn't think it would be that simple...

this would just be week numbers then, all the way to 52 or whatever? Also what day does the week change on?
Image Eternal Truth Ministry - Biblical Resources, Forums
Have mercy on me, O God, according to your unfailing love; according to your great compassion blot out my transgressions. - Psalm 51:1 http://www.zssites.net - ZS Sites Web Hosting
  • Vincent
  • Expert
  • Expert
  • User avatar
  • Joined: Dec 01, 2005
  • Posts: 722
  • Loc: Brisbane, Australia
  • Status: Offline

Post January 7th, 2006, 2:36 am

oops, misunderstood the question...
Code: [ Download ] [ Select ]
<?php

mysql_connect(localhost,"username","password");
@mysql_select_db($database) or die( "Unable to select database");


$week = date("W");
$query = "SELECT filename FROM audio_table WHERE week=$week";
$music_file = mysql_query($query);

if(file_exists("audio/$music_file")) {
 echo "<embed src='audio/$music_file' loop='true'>";
} else {
 echo "Sorry, there is no music for this week";
}

?>
  1. <?php
  2. mysql_connect(localhost,"username","password");
  3. @mysql_select_db($database) or die( "Unable to select database");
  4. $week = date("W");
  5. $query = "SELECT filename FROM audio_table WHERE week=$week";
  6. $music_file = mysql_query($query);
  7. if(file_exists("audio/$music_file")) {
  8.  echo "<embed src='audio/$music_file' loop='true'>";
  9. } else {
  10.  echo "Sorry, there is no music for this week";
  11. }
  12. ?>
"Chris" Vincent's Portfolio

Post January 7th, 2006, 2:47 am

this is a great start, I really appreciate it. What day of the week is this based off of? Sunday being a new week or Monday?

Now the totally unnecessary but slightly cool thing that I would like to do which could complicate things.

Is there a way to tell which day each week starts on?

Like my audio config page will list week 1-52, and I can select which audio file to play that week, but it would be nice to see week 1, January 1st, Week 2 Jaunary 7th ...etc...

Is this somewhat easy to do?
Image Eternal Truth Ministry - Biblical Resources, Forums
Have mercy on me, O God, according to your unfailing love; according to your great compassion blot out my transgressions. - Psalm 51:1 http://www.zssites.net - ZS Sites Web Hosting
  • Vincent
  • Expert
  • Expert
  • User avatar
  • Joined: Dec 01, 2005
  • Posts: 722
  • Loc: Brisbane, Australia
  • Status: Offline

Post January 7th, 2006, 2:57 am

i'll get started on it

and to answer your question, each week starts on a monday, though when the script is done, it won't matter
"Chris" Vincent's Portfolio
  • Vincent
  • Expert
  • Expert
  • User avatar
  • Joined: Dec 01, 2005
  • Posts: 722
  • Loc: Brisbane, Australia
  • Status: Offline

Post January 7th, 2006, 3:04 am

with this version, you would need to have 366 rows in the table, with the day_of_year starting at 1
Code: [ Download ] [ Select ]
<?php

mysql_connect(localhost,"username","password");
@mysql_select_db($database) or die( "Unable to select database");

$day_of_year = date("z");
$query = "SELECT filename FROM audio_table WHERE day_of_year=".($day_of_year+1).";
$music_file = mysql_query($query);

if(file_exists("audio/$music_file")) {
 echo "<embed src='audio/$music_file' loop='true'>";
} else {
 echo "Sorry, there is no music for this week";
}

?>
  1. <?php
  2. mysql_connect(localhost,"username","password");
  3. @mysql_select_db($database) or die( "Unable to select database");
  4. $day_of_year = date("z");
  5. $query = "SELECT filename FROM audio_table WHERE day_of_year=".($day_of_year+1).";
  6. $music_file = mysql_query($query);
  7. if(file_exists("audio/$music_file")) {
  8.  echo "<embed src='audio/$music_file' loop='true'>";
  9. } else {
  10.  echo "Sorry, there is no music for this week";
  11. }
  12. ?>


the good thing about this code is that you can have a different music file for each day
"Chris" Vincent's Portfolio
  • Vincent
  • Expert
  • Expert
  • User avatar
  • Joined: Dec 01, 2005
  • Posts: 722
  • Loc: Brisbane, Australia
  • Status: Offline

Post January 7th, 2006, 3:14 am

Also, this code should help with filling the empty gaps in the mysql table

Code: [ Download ] [ Select ]
// Code to fill gaps
<?php

$current_file = "somefile.mp3";

for($i=1;$i<367;$i++) {
 if($i<10) {
  $ii = "0".$i;
 } else {
  $ii = $i;
 }
 $query = "SELECT filename FROM audio_table WHERE day_of_year='$ii'";
 $file = mysql_query($query);
 if($file=="") {
  $query = "UPDATE audio_table SET filename='$current_file' WHERE day_of_year='$ii'";
  mysql_query($query);
 } else {
  $current_file = $file;
 }
?>
  1. // Code to fill gaps
  2. <?php
  3. $current_file = "somefile.mp3";
  4. for($i=1;$i<367;$i++) {
  5.  if($i<10) {
  6.   $ii = "0".$i;
  7.  } else {
  8.   $ii = $i;
  9.  }
  10.  $query = "SELECT filename FROM audio_table WHERE day_of_year='$ii'";
  11.  $file = mysql_query($query);
  12.  if($file=="") {
  13.   $query = "UPDATE audio_table SET filename='$current_file' WHERE day_of_year='$ii'";
  14.   mysql_query($query);
  15.  } else {
  16.   $current_file = $file;
  17.  }
  18. ?>
"Chris" Vincent's Portfolio

Post January 7th, 2006, 10:53 am

Thanks for all your help.

i'm not going to have daily audio files, just weekly. It isn't going to be music, but sermons. And I'll probably just make it play an m3u (or whatever the playlist extension is) instead of just the single file. That way in the future I might be able to add a song or two before/after the sermon.
Image Eternal Truth Ministry - Biblical Resources, Forums
Have mercy on me, O God, according to your unfailing love; according to your great compassion blot out my transgressions. - Psalm 51:1 http://www.zssites.net - ZS Sites Web Hosting

Post January 7th, 2006, 12:28 pm

I like this script that you made so far (in idea, I havent' actually made the php pages yet).


** Removed part of post, I figured out the removed part **


Also, I'm going to make another page that shows me all uploaded audio files that is listed in the database and what day number it will be played on then I can change it from there. But how do I know what day each number is? I would like to see a mini calendar or soemthing that says day 88 = March 29th. Not for every single day, but just like one day a week. Like have every monday listed as "Month Day = 88" then continue that for all 52 weeks.

Post January 7th, 2006, 12:55 pm

Ok, I just wrote out my idea on paper as best I can. Here is what I'm thinking of doing.

I will have a table with 366 entries. It will have 2 col. day_number and play_list.

I will be able to set day 88 to play list 3.

Then I will have a table called audio_lists and it will have the fields list_id, day_2_play1, day_2_play2 (4 total) and filename. The filename will point to an .m3u file which will lists the audio files I want played on that day.

Then when the player opens, it checks todays day, finds the last day with an entry in play_list. day 88 has a play_list entry of 3.

Then it loads the list_id 3 and plays the file name associated with that.

Does this sound good?

I will also have a 3rd table that stores the filenames and all the info for each song. So any song/sermon that is set to play in list_id 3 will be displayed.
Image Eternal Truth Ministry - Biblical Resources, Forums
Have mercy on me, O God, according to your unfailing love; according to your great compassion blot out my transgressions. - Psalm 51:1 http://www.zssites.net - ZS Sites Web Hosting
  • Vincent
  • Expert
  • Expert
  • User avatar
  • Joined: Dec 01, 2005
  • Posts: 722
  • Loc: Brisbane, Australia
  • Status: Offline

Post January 7th, 2006, 3:11 pm

Quote:
Then I will have a table called audio_lists and it will have the fields list_id, day_2_play1, day_2_play2 (4 total) and filename. The filename will point to an .m3u file which will lists the audio files I want played on that day.

I'm not quite sure about what your trying to do with this

Also, shouldn't the list of audio files be referenced from the list table?
like this - day_number - play_list - audio_id

Post January 7th, 2006, 3:16 pm

This will basically store all the information for the play list (instead of a individual song).

list_id = ID number for that list (I'm sure you knew that part :P )
day_2_play1 = stores the value of the day the file will be played (88 in the example above)
day_2_play2 = same as above, so the same file can be used multiple times at a later date
filename = points to the playlist filename "whatever.m3u"
Image Eternal Truth Ministry - Biblical Resources, Forums
Have mercy on me, O God, according to your unfailing love; according to your great compassion blot out my transgressions. - Psalm 51:1 http://www.zssites.net - ZS Sites Web Hosting
  • Vincent
  • Expert
  • Expert
  • User avatar
  • Joined: Dec 01, 2005
  • Posts: 722
  • Loc: Brisbane, Australia
  • Status: Offline

Post January 7th, 2006, 3:34 pm

if that's what you saying, shouldn't the first table with the play_list just have the list_id to reference it?
"Chris" Vincent's Portfolio

Post January 7th, 2006, 4:58 pm

The first table has the 366 entries, one for each day, and also the list_id for the playlist that will be played that day.

So the result would be
Day | list_id
88 | 3

Then list_id 3 info would be pulled up and played
Image Eternal Truth Ministry - Biblical Resources, Forums
Have mercy on me, O God, according to your unfailing love; according to your great compassion blot out my transgressions. - Psalm 51:1 http://www.zssites.net - ZS Sites Web Hosting
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post January 7th, 2006, 4:58 pm

Post Information

  • Total Posts in this topic: 43 posts
  • Users browsing this forum: No registered users and 108 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
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.