Is there a way to make a number change once every week?

Discussion in 'PHP' started by wwwbryan, Aug 6, 2009.

  1. #1
    I am trying to make some sort of PHP game if you will, that will choose a set of numbers and change every week. How would this be done in PHP+MySQL?

    I just want to find out about this stuff before I start actually coding it.
     
    wwwbryan, Aug 6, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well, you'd just use rand($min, $max) to get your number (do this multiple times) and save them to a text file. The use a cronjob once a week to write new numbers to the text file.
     
    premiumscripts, Aug 6, 2009 IP
  3. jamespv85

    jamespv85 Peon

    Messages:
    238
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    mt_rand() produces better values IMO, if you need to generate lots and lots. But simple functions rand() is enough.
     
    jamespv85, Aug 6, 2009 IP
  4. wwwbryan

    wwwbryan Well-Known Member

    Messages:
    181
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #4
    Yeah but I want it to automatically do this once a week.

    My idea is...

    Get the server's time,

    every 24x7 hours random number

    How would I accomplish that?
     
    wwwbryan, Aug 6, 2009 IP
  5. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I already told you, via a cronjob that you set up to execute once per week. (Like every sunday at 0:00)

    Google it.
     
    premiumscripts, Aug 6, 2009 IP
  6. wwwbryan

    wwwbryan Well-Known Member

    Messages:
    181
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #6
    Oh okay, sorry dude I was scanning through and I missed it. Thanks a bunch.
     
    wwwbryan, Aug 6, 2009 IP
  7. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #7
    Just generate a timestamp via time(). It will always be unique as long as you don't run it 2 times in one second.
     
    jestep, Aug 6, 2009 IP
  8. wwwbryan

    wwwbryan Well-Known Member

    Messages:
    181
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #8
    Any idea how to get the Server's time instead of the user's computer time?
     
    wwwbryan, Aug 6, 2009 IP
  9. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Well, time() will generate the server's time..
     
    premiumscripts, Aug 6, 2009 IP
  10. wwwbryan

    wwwbryan Well-Known Member

    Messages:
    181
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #10
    Maybe I am thinking about date().
     
    wwwbryan, Aug 6, 2009 IP
  11. oop

    oop Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    i think this is what your trying to do..

    on your game lets say i just registered

    
    
    //Here you processed my register for etc
    
    now what you want to do is insert the time into the users table so we know it has been updated
    
    then everytime the user logs in to your game do summat like this
    
    if($row['last_update_time'] < ($row['last_update_time'])+(Calculate 7 days in mktime() here ))){
    //then do your update thing here and then update the database with the new time()
    }
    
    
    PHP:
     
    oop, Aug 7, 2009 IP
  12. wwwbryan

    wwwbryan Well-Known Member

    Messages:
    181
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #12
    Umm no I just want to get the server's timestamp. :)
     
    wwwbryan, Aug 7, 2009 IP