grucker Posted June 16, 2012 Share Posted June 16, 2012 I would like a little help with the code to load a different page depending on the month. I have done it for date but haven't mastered the month way Regards Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/ Share on other sites More sharing options...
Barand Posted June 16, 2012 Share Posted June 16, 2012 I'll leave this one to those with greater psychic abilities than I have. Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354384 Share on other sites More sharing options...
grucker Posted June 16, 2012 Author Share Posted June 16, 2012 I have got this code I just wondered if there was a better way. <?php $month = date("m"); switch($month) { case 06: include('includes/no.php'); break; case 07: include('includes/yes.php'); break; } ?> Mod edit: change [m][/m] (manual/doc) tags to tags Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354386 Share on other sites More sharing options...
cpd Posted June 16, 2012 Share Posted June 16, 2012 There are so many different answers to the question your asking. It comes down to your style of programming and your current methods. If your including files like this in your system you shouldn't really change the way your doing it as you then get inconsistencies with your code. Also, wrap your code in code tags - [ code ] without spaces - because what you've done so far makes it difficult to help you at all. Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354408 Share on other sites More sharing options...
Mahngiel Posted June 17, 2012 Share Posted June 17, 2012 I just wondered if there was a better way. Better is subjective. <?php $month = date("m"); include_once('includes/' . $month . '-index.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354538 Share on other sites More sharing options...
grucker Posted June 17, 2012 Author Share Posted June 17, 2012 Like that better. How does one show 3 months of one file then 3 months of another and so on for year? On a different matter. Is it possible to show an image ? I have only succeeded by using echo. Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354545 Share on other sites More sharing options...
Porl123 Posted June 17, 2012 Share Posted June 17, 2012 $pages = array("jan.php", "feb.php", "mar.php", "apr.php", "may.php", "jun.php", "jul.php", "aug.php", "sep.php", "oct.php", "nov.php", "dec.php"); $month = date("m"); include($pages[$month - 1]); Probably overkill now. Just giving you another option. Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354546 Share on other sites More sharing options...
PFMaBiSmAd Posted June 17, 2012 Share Posted June 17, 2012 Here's a slightly different slant on the problem. You should not have a bunch of different files that only differ in the content they contain. You should have one file, then use the power of the php server side scripting language to dynamically get or produce the correct content within that one file. This will mean that your displayed output will be consistent and easier to maintain or alter. To change the layout, you only have one place that needs changing and to add or change the content, you simply add or change the data that defines the content. Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354547 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 17, 2012 Share Posted June 17, 2012 $pages = array("jan.php", "feb.php", "mar.php", "apr.php", "may.php", "jun.php", "jul.php", "aug.php", "sep.php", "oct.php", "nov.php", "dec.php"); $month = date("m"); include($pages[$month - 1]); Probably overkill now. Just giving you another option. More consolidated: $pages = array("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"); $month = date("m"); include "$pages[$month - 1]".'.php'; But: Here's a slightly different slant on the problem. You should not have a bunch of different files that only differ in the content they contain. You should have one file, then use the power of the php server side scripting language to dynamically get or produce the correct content within that one file. This will mean that your displayed output will be consistent and easier to maintain or alter. To change the layout, you only have one place that needs changing and to add or change the content, you simply add or change the data that defines the content. Agree 100%. Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354548 Share on other sites More sharing options...
grucker Posted June 17, 2012 Author Share Posted June 17, 2012 You should not have a bunch of different files that only differ in the content they contain. You should have one file, then use the power of the php server side scripting language to dynamically get or produce the correct content within that one file. This will mean that your displayed output will be consistent and easier to maintain or alter. To change the layout, you only have one place that needs changing and to add or change the content, you simply add or change the data that defines the content. Must be too old, I do not know what you mean. I use the include in the index.php page. Usually a swf file that changes due to season. Would you explain what you meant in a different context and then I may understand. I still don't know about including images. Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354549 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 18, 2012 Share Posted June 18, 2012 You should not have a bunch of different files that only differ in the content they contain. You should have one file, then use the power of the php server side scripting language to dynamically get or produce the correct content within that one file. This will mean that your displayed output will be consistent and easier to maintain or alter. To change the layout, you only have one place that needs changing and to add or change the content, you simply add or change the data that defines the content. Must be too old, I do not know what you mean. I use the include in the index.php page. Usually a swf file that changes due to season. Would you explain what you meant in a different context and then I may understand. I still don't know about including images. Instead of having multiple pages you can do one page with something like this in it: switched_content.php $month=$_GET['month']; $month=strtolower($month); //Only necessary if switch statement cases are case sensitive - not sure switch ($month) case "jan": $data="content here"; break; case "feb": $data="content here"; break; case "mar": $data="content here"; break; case "apr": $data="content here"; break; case "jun": $data="content here"; break; case "jul": $data="content here"; break; case "aug": $data="content here"; break; etc... Then on the page you want to include the item in: $_GET['month']=date("M"); include 'switched_content.php'; echo $data; This would pull the data inside the switch statement for the case of the current month. You could also condense it down to one file, but two files in my opinion is the way to go, keeps the bulk of the code out of the display file. Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354749 Share on other sites More sharing options...
Mahngiel Posted June 18, 2012 Share Posted June 18, 2012 Usually a swf file that changes due to season. ... I still don't know about including images. Do you want to change a page or an image (flash or otherwise) depending on month? Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354770 Share on other sites More sharing options...
grucker Posted June 18, 2012 Author Share Posted June 18, 2012 Instead of having multiple pages you can do one page with something like this in it: switched_content.php $month=$_GET['month']; $month=strtolower($month); //Only necessary if switch statement cases are case sensitive - not sure switch ($month) case "jan": $data="content here"; break; case "feb": $data="content here"; break; case "mar": $data="content here"; break; case "apr": $data="content here"; break; case "jun": $data="content here"; break; case "jul": $data="content here"; break; case "aug": $data="content here"; break; etc... Then on the page you want to include the item in: $_GET['month']=date("M"); include 'switched_content.php'; echo $data; This would pull the data inside the switch statement for the case of the current month. You could also condense it down to one file, but two files in my opinion is the way to go, keeps the bulk of the code out of the display file. That seems to be the format I will use. The code didn't work but the idea is good. For some reason I had to insert{ } and change from jun to 06 and on the page M to m and it worked fine. I also managed to include an image with your idea. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354772 Share on other sites More sharing options...
grucker Posted June 18, 2012 Author Share Posted June 18, 2012 Usually a swf file that changes due to season. ... I still don't know about including images. Do you want to change a page or an image (flash or otherwise) depending on month? include ('<img src='images/test.png'>'); didnt work echo "<img src='images/test.png'> "; did work. just wanted to know how to insert image to include Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354773 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 18, 2012 Share Posted June 18, 2012 For some reason I had to insert{ } You mean after the switch condition, and the end of the switch; like this: switch ($month){ case "jan": $data="content here"; break; case "feb": $data="content here"; break; case "mar": $data="content here"; break; case "apr": $data="content here"; break; case "jun": $data="content here"; break; case "jul": $data="content here"; break; case "aug": $data="content here"; break; etc... } Yeah, I forgot those. That is correct. Just as a reminder, there's a "Topic Solved" button below the thread on the left. Click that once you find a solution. Quote Link to comment https://forums.phpfreaks.com/topic/264287-change-page-depending-on-month/#findComment-1354774 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.