niranjnn01 Posted August 12, 2008 Share Posted August 12, 2008 Hello, I want to generate a random date, and use it for 24 hrs, to display a section on my website. like todays picture. after 24 hours, the script should fetch another random date, and keep it for 24 hrs. This is my logic... if(24 hrs not over yet) { get picture from table where date= $random_date } else { generate a new random date, and get picture from table where date = $new_random_date } How could i achieve this? could anyone suggest some idea so that i can work on it? Thanks for the help.. Link to comment https://forums.phpfreaks.com/topic/119277-solved-one-random-date-per-day-want-an-idea/ Share on other sites More sharing options...
kenrbnsn Posted August 12, 2008 Share Posted August 12, 2008 You need to store the selection somewhere outside the script. A database entry would be best. And then check for when the entry was created. If it's more than 24 hours, get and store a new one. If it's not more than 24 hour old, just use it. Ken Link to comment https://forums.phpfreaks.com/topic/119277-solved-one-random-date-per-day-want-an-idea/#findComment-614429 Share on other sites More sharing options...
PHPTOM Posted August 12, 2008 Share Posted August 12, 2008 Maybe not the best but using a cron job so at midnight it fetches a new picture or whatever out of an array and maybe if you don't have a database put it into a flat file. Not the way I would do it, but certainly possible. Link to comment https://forums.phpfreaks.com/topic/119277-solved-one-random-date-per-day-want-an-idea/#findComment-614431 Share on other sites More sharing options...
discomatt Posted August 12, 2008 Share Posted August 12, 2008 I'd make a pseudo-random algorithm based on the date. <?php $today = date( 'dmY' ); $randomDate = make_date( $today ); echo date( 'Y - m - d', $randomDate ); function make_date( $input ) { $stamp = 1; $hash = sha1( $input ); for( $i = 0, $c = strlen($hash); $i < $c; $i++ ) { $stamp += ord( $hash[$i] ) * 400000; } return $stamp; } ?> Link to comment https://forums.phpfreaks.com/topic/119277-solved-one-random-date-per-day-want-an-idea/#findComment-614439 Share on other sites More sharing options...
niranjnn01 Posted August 12, 2008 Author Share Posted August 12, 2008 Hello All, Thank you for al your quick suggestions .I appretiate that.. I think I will go with discomatts idea... and ofcourse the script too... Thanks a lot man.. Regards Link to comment https://forums.phpfreaks.com/topic/119277-solved-one-random-date-per-day-want-an-idea/#findComment-614446 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.