Page 1 of 1

2 variables, random numbers and timestamps, read/write files

Posted: Sat May 30, 2009 6:28 am
by karossii
I would like to implement a small php file to do the following when it is called...
  • read an XML file or text file and pull in two variables.
    • the first variable (VAR1) is a number
    • the second variable (VAR2) is a time-stamp
  • compare the current time-stamp to VAR2
    • if the times are more than 1 day apart, add a random number between 180 and 960 for each day apart to VAR1
    • if the times are between 1 hour and 1 day apart, add a random number between 6 and 36 for each hour apart to VAR1
    • if the times are between 1 minute and 1 hour, add a random number between 3 and 12 to VAR1
    • if the times are less than 1 minute apart, add a random number between 1and 5 to VAR1
  • update VAR2 with the current time-stamp
  • In case it isn't obvious, write the updated VAR1 and VAR2 back to the file and close it
This will be integrated into a flash movie I am making... I could use a SQL database instead of a flatfile, but I would rather not.

Thanks for any help you can provide!!!

Re: this should be simple, I think...?

Posted: Sat May 30, 2009 6:39 am
by jayshields
What's the problem?

Just look at rand() and the date functions in PHP.

Also, change your thread title to something more descriptive of your thread content.

Re: this should be simple, I think...?

Posted: Sat May 30, 2009 8:35 am
by top10ingoogle
<?php

$now = date('h:i:s A');

if(($now - $var2) < 24hrs) {
$rand = rand(180, 960);
$var2 = $var2 + $rand;
}

// and so on....
?>

non working code but something like this should work of course you'd still have to format the date for seconds or minutes and execute the remaing functions based on var output.

Re: this should be simple, I think...?

Posted: Mon Jun 01, 2009 12:47 am
by karossii
jayshields wrote:What's the problem?

Just look at rand() and the date functions in PHP.

Also, change your thread title to something more descriptive of your thread content.
Done and done.

I need three basic pieces of help. Very basic.
1) How do I read/write the file (and how should it be formatted)?
2) How do I compare the timestamps?
3) I am fairly certain this one I can handle, but just in case... how do I set the random number functions?

Thanks!