Forum Moderators: coopster
$banner_no = (rand()%(count($s_con)-1));
Just so you know what the above does, gets a random number which is in the content of my file. for instance if I have
1-some text
2-different text
3-some other text
It grabs one of these numbers and the text along with it to display randomly. I would like it to display by day and in order instead.
So it would be:
$day = 3 + floor(mktime() / (60 * 60 * 24));
$chosen = $day % 7;
if you wanted $chosen to take a value from 0 to 6 representing Sunday to Saturday.
I've tested that and it seems to work. Change the % 7 to % $number_of_options to suit you.
[edited by: UserFriendly at 4:58 pm (utc) on Sep. 3, 2006]
<?php
$seed = floor(time()/24*60*60); //number of days since 1970
srand($seed); //seed the random number generator with this
$item = (rand()%(count($s_con)-1)); //as previously
?>
By setting the seed of the random numer generator before using rand() you should be able to fix the number for a given seed, by using the seed as the day number you then fix the value of rand() for the whole day.
Yes I only want it to change once per day. And for it to change to the next one in sequential number order, the next day. But having a different one for 31 days would be nice. Thank you very much for your help!