mumford Posted September 14, 2006 Share Posted September 14, 2006 HiI am VERY new tp php, and found this script on php freaks, it is a randomizer script[code]<?/* Directory Structure/index1.htm/index2.htm*/srand((double)microtime()*1000000); $num = rand(1,2);include ('index'.$num.'.htm');?>[/code]What I need to happen on my website is 3 blocks of text each in its own div to change every day (5 days to be precise), I got the above to work but as I said it is just a randomizer so each time you refresh it changes.Also my dynamic content pages will sit in its own folder, and I would like to name the pages depending on what they are, eg, capetown.htm, garden-route.htmDoes that make sense, hope someone can help me!thanks Quote Link to comment https://forums.phpfreaks.com/topic/20722-rotate-dynamic-content-every-day/ Share on other sites More sharing options...
Jocka Posted September 14, 2006 Share Posted September 14, 2006 it might be best for the script to maybe check for a time of day?For example. If it is past midnight, the date is different, and the info hasn't already been changed, then save information in the database. (or even a file, who cares in this situation).then for that entire day it will show "whatever.htm" and at 12 midnight (or later) whenevery someone opens the page, the first person to open it after midnight, it will set this new information accordingly.The things you'll need to look into to make this work is file reading/writing and date functions. that should be enough to get that idea done. Quote Link to comment https://forums.phpfreaks.com/topic/20722-rotate-dynamic-content-every-day/#findComment-91693 Share on other sites More sharing options...
gerkintrigg Posted September 14, 2006 Share Posted September 14, 2006 or use a counter script from a database field like:switch ($row['counter']){case 1:echo 'stuff #1';break;}and keep doing that for each instancethen if it's the following day, update the database using a timestamp checker. Quote Link to comment https://forums.phpfreaks.com/topic/20722-rotate-dynamic-content-every-day/#findComment-91700 Share on other sites More sharing options...
mumford Posted September 14, 2006 Author Share Posted September 14, 2006 Thanks fo rthe quick replies, like I sadi I know very lttle PHP (at the moment!)So I would have to create a database where all of my text divs would sit, then call them from the homepage? Quote Link to comment https://forums.phpfreaks.com/topic/20722-rotate-dynamic-content-every-day/#findComment-91702 Share on other sites More sharing options...
mumford Posted September 14, 2006 Author Share Posted September 14, 2006 Can anyone else shed some more light on how I go about setting this up to switch content on a daily basis, do I really have to set up a database?....... there will only be about 5 alternative text blocks Quote Link to comment https://forums.phpfreaks.com/topic/20722-rotate-dynamic-content-every-day/#findComment-91752 Share on other sites More sharing options...
AndyB Posted September 14, 2006 Share Posted September 14, 2006 The sort of thing I'd do is use php to get today's date and determine what day number of the year it is. Then I'd modulo 5 that and based on the remainder, I'd include day0.php, day1.php etc. No database needed, no counter needed. Quote Link to comment https://forums.phpfreaks.com/topic/20722-rotate-dynamic-content-every-day/#findComment-91785 Share on other sites More sharing options...
mumford Posted September 14, 2006 Author Share Posted September 14, 2006 sounds exactly what i need, but I dont even know where to start to get that working, your help or guidance would be much appreciated.thanks Quote Link to comment https://forums.phpfreaks.com/topic/20722-rotate-dynamic-content-every-day/#findComment-91794 Share on other sites More sharing options...
AndyB Posted September 14, 2006 Share Posted September 14, 2006 [code]<?php$doty = date("z"); // day of the year$doty_remainder = $doty % 5 ; // remainder of day of the year divided by 5$the_file = "path/to/my/files/news_". $doty_remainder. ".php"; // edit path info to suitinclude($the_file);?>[/code]That'll need files news_0.php, news_1.php ..... news_4.php. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/20722-rotate-dynamic-content-every-day/#findComment-91811 Share on other sites More sharing options...
mumford Posted September 14, 2006 Author Share Posted September 14, 2006 Andy B, that looks like it will be the best response I have received over 2 days, thank you!I suppose if I need to have other items that rotate on a daily basis I just inser the same code but change the filenames eg[code]<?php$doty = date("z"); // day of the year$doty_remainder = $doty % 5 ; // remainder of day of the year divided by 5$the_file = "[b]dynamic/offers[/b]_". $doty_remainder. ".php"; // edit path info to suitinclude($the_file);?>[/code]Also as a matter of interest if I did want those 5 pages to rotate randomly is there a way of adjusting the code you gave or would it be something different entirely?Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/20722-rotate-dynamic-content-every-day/#findComment-91864 Share on other sites More sharing options...
AndyB Posted September 14, 2006 Share Posted September 14, 2006 Answer to the first question is "Yes".as to the second: to have a randomly selected page (from a lsit), I'd use code like this:[code]<?php$pages = array("page1.php", "gardening.php", "fishing.php", "whatever.php"); // as many as you want$the_file = $pages[rand(0,count($pages)-1)]; // select a random page from the arrayinclude($the_file);?>[/code]You can add file names to the array and the rest of the code can remain as written. Quote Link to comment https://forums.phpfreaks.com/topic/20722-rotate-dynamic-content-every-day/#findComment-91947 Share on other sites More sharing options...
mumford Posted September 15, 2006 Author Share Posted September 15, 2006 great stuff! - thanks again for your help Quote Link to comment https://forums.phpfreaks.com/topic/20722-rotate-dynamic-content-every-day/#findComment-92259 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.