Jump to content

display a video based on a date range


Pghmediaking

Recommended Posts

I am new to PHP so bare with me but I am trying to display videos based on a date range without using a database. The videos are independently housed inside individual .php files that I am using as includes. Can anyone take a look into what Im doing so that I can figure out if my techniques is correct. Below is the coding that I have completed:

 

---------------------------------------------------------------------------------------------------------------------

The include files are setup in this manor: 

 

video_name1.php contains this coding(as do all the other include files:

 

<video width="640" height="480" controls>
     <source src="media/ogg/easter_720x480.ogv" type="video/ogg">
     <source src="media/mp4/easter_720x480.mp4" type="video/mp4">
     <source src="media/webm/easter_720x480.webm" type="video/webm">
     <source src="media/wmv/easter_720x480.wmv" type="video/wmv">
         <object data="movie.mp4" width="640" height="480">
            <embed width="640" height="480" src="media/player.swf"></embed>
        </object>
</video>

---------------------------------------------------------------------------------------------------------------------

 

My php constructed to complete the task:

 

<?php
                            $video_name1="includes/video_name1.php";
                            $video_name2="includes/video_name2.php";
                            $video_name3="includes/video_name2.php";
                            $video_name4="includes/video_name2.php";
                            $video_name5="includes/video_name2.php";
                            $video_name6="includes/video_name2.php";
                        ?>
 
                        <?php
                            date_default_timezone_set('America/New_York');
                            
                            $today = strtotime(date('Y-m-d'));
                            
                            $startApr = strtotime(date('Y') . '-04-01');
                            $endMay = strtotime(date('Y') . '-5-31');
                            
                            $startJune = strtotime(date('Y') . '-06-01');
                            $endJuly = strtotime(date('Y') . '-7-31');
                            
                            $startAug = strtotime(date('Y') . '-08-01');
                            $endSept = strtotime(date('Y') . '-9-30');
                            
                            $startOct = strtotime(date('Y') . '-10-01');
                            $endNov = strtotime(date('Y') . '-11-30');
                            
                            $startDec = strtotime(date('Y') . '-12-01');
                            $endJan = strtotime(date('Y') . '-1-31');
                            
                            $startFeb = strtotime(date('Y') . '-2-01');
                            $endMarch = strtotime(date('Y') . '-3-31');
                            
                            if($today >= $startApr && $today <= $endMay) {
                                    include($video_name1);
                                }
                            else if($today >= $startJune && $today <= $endJuly)
                                {
                                    include($video_name2);
                                }
                            else if($today >= $startAug && $today <= $endSept)
                                {
                                    include($video_name3);
                                }
                            else if($today >= $startOct && $today <= $endNov)
                                {
                                    include($video_name4);
                                }
                            else if($today >= $startDec && $today <= $endJan)
                                {
                                    include($video_name5);
                                }
                            else if($today >= $startFeb && $today <= $endMarch)
                                {
                                    include($video_name6);
                                }
                        ?>

Link to comment
Share on other sites

  • 3 weeks later...

So I posted this topic some time ago, roughly a month, and not one person responded. Is this what is to be expected from this online community. I am looking for a site that helps new developers learn while also contributing when I can. This had almost 50 views and not one response.

Link to comment
Share on other sites

if you want to match just the month number(s) to values, you would use a lookup array to do that -
 

$map[4] = $video_name1;
$map[5] = $video_name1;
...

$today = date('n'); // 1-12

include $map[$today];

if you want to use any arbitrary month-day start and end you would use an array that lists the start and end values that you can loop through to find the matching entry -

$map[] = array('04-01','05-31',$video_name1);
$map[] = array('06-01','07-31',$video_name2);
...
$map[] = array('12-01','12-31',$video_name5); // break up any value spanning the end/start of the year
$map[] = array('01-01','01-31',$video_name5);
...

$today = date('m-d'); // 01-01 - 12-31
foreach($map as $arr){
    if($today >= $arr[0] && $today <= $arr[1]){
        include $arr[2];
        break;
    }
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.