Jump to content

[SOLVED] One random date per day - want an idea


niranjnn01

Recommended Posts

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..

 

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

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;
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.