flipper828 Posted September 23, 2013 Share Posted September 23, 2013 Hello to everyone! I have a webpage that displays a number. I want this number to change every 24 hours for anyone that visits the site. Right now, I am manually changing this number each day. For the last year, I have searched help websites, consulted many many books and consulted with a couple of programmers I know that seem to not even understand what I am talking about. Would someone give me a hand in learning how to do this? Your help would be so much appreciated. To give you an idea of my knowledge level, what I have learned comes from an online php beginner and intermediate class and then some playing aorund and testing from books. Little, I know, and I apologize in advanced. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/ Share on other sites More sharing options...
AbraCadaver Posted September 23, 2013 Share Posted September 23, 2013 Where do the numbers come from? Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450913 Share on other sites More sharing options...
flipper828 Posted September 23, 2013 Author Share Posted September 23, 2013 Thank you for being so quick! I just pluck them out of the air when updating the site. However, I have read something about putting a list of numbers in a .txt file. There is no database connected to this site so the .txt file (if that is an option) would probably be the easiest. I hope I am making sense to you. Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450916 Share on other sites More sharing options...
AbraCadaver Posted September 23, 2013 Share Posted September 23, 2013 Thank you for being so quick! I just pluck them out of the air when updating the site. However, I have read something about putting a list of numbers in a .txt file. There is no database connected to this site so the .txt file (if that is an option) would probably be the easiest. I hope I am making sense to you. It's pretty easy to do, but can the numbers just be random? What parameters do they have? Are they any number between 0 and infinity or what? Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450917 Share on other sites More sharing options...
flipper828 Posted September 23, 2013 Author Share Posted September 23, 2013 Any random number between 50 and 5000. I don't understand what you're asking about parameters. I'm sorry. Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450921 Share on other sites More sharing options...
AbraCadaver Posted September 23, 2013 Share Posted September 23, 2013 Well, I meant the rules or conditions pertaining to the numbers. I guess I'm trying to get more information. When does the 24 hours start? Midnight? Noon? Another time? Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450924 Share on other sites More sharing options...
AbraCadaver Posted September 23, 2013 Share Posted September 23, 2013 Can the numbers be reused later? Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450930 Share on other sites More sharing options...
Ch0cu3r Posted September 23, 2013 Share Posted September 23, 2013 Is this number a part of a date? You could look into using the date function http://php.net/date You need to give us more info of what this number does. Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450931 Share on other sites More sharing options...
flipper828 Posted September 23, 2013 Author Share Posted September 23, 2013 Oh Ok. The numbers can be reused and the ideally, I would like it to change at midnight EST. The number is not going to do anything but inform the visitor about the number of changes that have happened since the day before. It will have a hyperlink to a .pdf I have but I know how to do the hyperlink. Thank you both so much. I know this has to be frustrating. Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450934 Share on other sites More sharing options...
AbraCadaver Posted September 23, 2013 Share Posted September 23, 2013 So you are going to use a random number for the number of changes? So this is not meant to be accurate? Just something to get them to download the pdf? Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450936 Share on other sites More sharing options...
Ch0cu3r Posted September 23, 2013 Share Posted September 23, 2013 Still need more info. What changes? Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450937 Share on other sites More sharing options...
flipper828 Posted September 23, 2013 Author Share Posted September 23, 2013 (edited) The number does not have to be accurate to the number of changes to a data point spreadsheet I have available each day. However, that IS a future project. For now, I just want a different number to display each day which is linked to a .pdf which explains the data points on the spreadsheet. Does this make more sense? *fingers crossed* Edited September 23, 2013 by flipper828 Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450940 Share on other sites More sharing options...
AbraCadaver Posted September 23, 2013 Share Posted September 23, 2013 Not extensively tested, but try: date_default_timezone_set('America/New_York'); $file = 'number.txt'; $date = $number = 0; if(file_exists($file)) { list($date, $number) = file($file, FILE_IGNORE_NEW_LINES); } if((time()) > strtotime('+24 hours', $date)) { $date = strtotime('midnight'); $number = mt_rand(50, 5000); file_put_contents($file, "$date\n$number"); } echo $number; Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450944 Share on other sites More sharing options...
Ch0cu3r Posted September 23, 2013 Share Posted September 23, 2013 You've lost me. date('z'); will give you the day of the year. It'll reset to 1 on 1st Jan 2014 tho. Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450946 Share on other sites More sharing options...
kicken Posted September 23, 2013 Share Posted September 23, 2013 mt_rand - you can use that to just generate a random number. mt_srand - This seeds the random number generator with an initial value. Using the same seed will cause mt_rand to generate the same number date - This will let you get the current date. So, to get a random number that changes each day, seed the number generator with the current date and then call mt_rand. Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450947 Share on other sites More sharing options...
Solution AbraCadaver Posted September 23, 2013 Solution Share Posted September 23, 2013 mt_rand - you can use that to just generate a random number. mt_srand - This seeds the random number generator with an initial value. Using the same seed will cause mt_rand to generate the same number date - This will let you get the current date. So, to get a random number that changes each day, seed the number generator with the current date and then call mt_rand. I'll be damned! date_default_timezone_set('America/New_York'); mt_srand(date('Ymd')); $number = mt_rand(50, 5000); mt_srand(); //reset for other calls echo $number; Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1450949 Share on other sites More sharing options...
flipper828 Posted September 24, 2013 Author Share Posted September 24, 2013 Oh thank you so much everyone! I'm off to try this and I'll be back. You people have always been to nice and kind! Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1451043 Share on other sites More sharing options...
flipper828 Posted September 24, 2013 Author Share Posted September 24, 2013 Thank you so much Kicken and AbraCadaver for your generosity! Surprise....I've not hear of mt_rand and mt_srand in my research and studies. Thank you for the links. I want to go back and study these soon. Quote Link to comment https://forums.phpfreaks.com/topic/282392-changing-a-number-every-24-hours/#findComment-1451047 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.