robert.access Posted February 6, 2008 Share Posted February 6, 2008 can anyone tell me the script to have a random image every day and a script to generate random numbers between 1 and 10 but to stay on page all day end randomize the next day???? thank you Quote Link to comment https://forums.phpfreaks.com/topic/89764-random-image-per-day-help/ Share on other sites More sharing options...
Caesar Posted April 16, 2008 Share Posted April 16, 2008 Look into using the rand() function. And you can randomize the image once a day, using cookies. Provided the user does not delete the cookie, the image will not be reloaded until the next day. Quote Link to comment https://forums.phpfreaks.com/topic/89764-random-image-per-day-help/#findComment-518097 Share on other sites More sharing options...
Northern Flame Posted April 16, 2008 Share Posted April 16, 2008 or you can have a cron job at the end of each day that will select a random image, rand(1, 10) and insert the value into a database where you can then grab the value and display the image Quote Link to comment https://forums.phpfreaks.com/topic/89764-random-image-per-day-help/#findComment-518120 Share on other sites More sharing options...
doni49 Posted April 16, 2008 Share Posted April 16, 2008 If you really just want a different image every day, you could use the date function to give you a new filename every day. No cookies needed. No cron job needed. It would just run when the page loads. How many images do you have to choose from? EDIT: never mind--I didn't read the OP close enough. Sorry Quote Link to comment https://forums.phpfreaks.com/topic/89764-random-image-per-day-help/#findComment-518125 Share on other sites More sharing options...
laffin Posted April 16, 2008 Share Posted April 16, 2008 Use the date function with z Parameter. the z Parameter returns the day of year. now question is, how use a limiter to select a set number of images. quick coding sample <?php header('Content-type: text/plain'); $ads=array('ad01','ad02','ad03','ad04','ad05','ad06','ad07','ad08'); $today=intval(date('z')); $num_ads=count($ads); $i=0; while($i++<10) { $todays_ad=$ads[($today % $num_ads)]; echo "Todays Ad: $todays_ad\n"; $today++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89764-random-image-per-day-help/#findComment-518138 Share on other sites More sharing options...
redarrow Posted April 16, 2008 Share Posted April 16, 2008 Here a nice way m8..... <?php $d=array("1"=>"day1.gif","day2.gif","day3.gif","day4.gif","day5.gif","day6.gif","day7.gif","day8.gif" ,"day9.gif","day10.gif","day11.gif","day12.gif","day13.gif","day14.gif","day15.gif","day16.gif", "day17.gif","day18.gif","day19.gif","day20.gif","day21.gif","day22.gif","day23.gif","day24.gif", "day25.gif","day26.gif","day27.gif","day28.gif","day29.gif","day30.gif","day31.gif"); $date=date("d"); foreach ($d as $key => $day){ if($date==$key){ echo "$key is $day<br>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89764-random-image-per-day-help/#findComment-518146 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.