I have a small problem. I'm still relatively new to this, so please have mercy.
I'm trying to get php to check whether a datafile has been uploaded to MySQL in the last, say, 10 minutes because if it has I don't want to load it again ... because it takes 20 or more seconds to do so.
The code I have written for this is at the bottom.
If the file hasn't been uploaded within the last 10 min, the program should delete the contents of the table and then upload new values.
the whole delete and re-upload of files works fine, but I can't seem to get the thing to recognize if the files have been uploaded in the last 10 minutes.
"time" is the field which holds the value given by the function "time()".
I call this out of the database without a problem. But when I try to equate it to the present time (time()) minus 1000 "clicks" -- ok, it's a little over 10 minutes -- to determine if 1000 clicks has passed, I can't seem to get the thing to work. It compiles fine, but treats every run through as if there were no "if" statement. Just goes through and deletes and re-uploads.
Is it necessary to have an "else" with an "if"? If so, what do I say if I want "else" to be nothing? (i.e. if (true) {} else do nothing.)
--------
$time = time();
$result = mysql_query("SELECT time FROM complete_stock_quotes",$db);
$myrow = mysql_fetch_array($result);
if (($myrow["time"]) >= (time()-1000)){
mysql_query("DELETE FROM complete_stock_quotes",$db);
for ($i = 0; $i < sizeof($tickers); $i++) {
$open = fopen("http://quote.yahoo.com/d/quotes.csv?s=$tickers[$i]&f=sl1d1t1c1ohgv&e=.csv", "r");
$read = fread($open, 2000);
fclose($open);
$read = str_replace("\"", "", $read);
$read = explode(",", $read);
if (($read[4] != 0) and ($read[5] != 0)) {
$percent=$read[4]/$read[5]*100;
} else {
$percent = 0;
}
$query = "INSERT into complete_stock_quotes (ticker, lastTrade, delta, volume, percent, time) VALUES ('$read[0]','$read[1]','$read[4]','$read[8]','$percent', '$time')";
mysql_query($query, $db);
}
}
thanks,
cdherold
I'm trying to get php to check whether a datafile has been uploaded to MySQL in the last, say, 10 minutes because if it has I don't want to load it again ... because it takes 20 or more seconds to do so.
The code I have written for this is at the bottom.
If the file hasn't been uploaded within the last 10 min, the program should delete the contents of the table and then upload new values.
the whole delete and re-upload of files works fine, but I can't seem to get the thing to recognize if the files have been uploaded in the last 10 minutes.
"time" is the field which holds the value given by the function "time()".
I call this out of the database without a problem. But when I try to equate it to the present time (time()) minus 1000 "clicks" -- ok, it's a little over 10 minutes -- to determine if 1000 clicks has passed, I can't seem to get the thing to work. It compiles fine, but treats every run through as if there were no "if" statement. Just goes through and deletes and re-uploads.
Is it necessary to have an "else" with an "if"? If so, what do I say if I want "else" to be nothing? (i.e. if (true) {} else do nothing.)
--------
$time = time();
$result = mysql_query("SELECT time FROM complete_stock_quotes",$db);
$myrow = mysql_fetch_array($result);
if (($myrow["time"]) >= (time()-1000)){
mysql_query("DELETE FROM complete_stock_quotes",$db);
for ($i = 0; $i < sizeof($tickers); $i++) {
$open = fopen("http://quote.yahoo.com/d/quotes.csv?s=$tickers[$i]&f=sl1d1t1c1ohgv&e=.csv", "r");
$read = fread($open, 2000);
fclose($open);
$read = str_replace("\"", "", $read);
$read = explode(",", $read);
if (($read[4] != 0) and ($read[5] != 0)) {
$percent=$read[4]/$read[5]*100;
} else {
$percent = 0;
}
$query = "INSERT into complete_stock_quotes (ticker, lastTrade, delta, volume, percent, time) VALUES ('$read[0]','$read[1]','$read[4]','$read[8]','$percent', '$time')";
mysql_query($query, $db);
}
}
thanks,
cdherold