Page 1 of 1
Need experts opinion.
Posted: Sun Sep 17, 2006 11:59 pm
by akimm
This code is acting slightly off (not showing when the file has been updated, indicating a new article), because I had added some logic, which I thought would speed it up, and assure it to work, but has messed it up, somewhere.
My purpose for it, is to view the file within the $file variable, which is my journal file, basically i want it to view the last time it was updated, IE: last time I used fwrite to add an extra journal entry. If so I want it to then print that when i include this file on my main page. Otherwise, I want it to leave it alone. Hence the evaluation "< 2" with the time.
Thanks for any advice in advance
Code: Select all
<?php
$img = "<img src=http://www.akimm.com/images/new1.gif>";
$file = "journal06/journal/journalaug_sept.txt";
if(file_exists($file) {
if(round(time()) - fileatime($file)/3600/24 =< 2) {
echo "<ul>" . "<li>" . $img . "<a href=http://www.akimm.com/journal06/journal.php>" . "Click to view new journal entrys " .
"</a>" . "</li>" . "</ul>";
}
}
?>
Posted: Mon Sep 18, 2006 1:45 am
by aaronhall
is missing a closing parenthese.
Code: Select all
if(round(time()) - fileatime($file)/3600/24 =< 2) {
Less than or equal to is "<=" not "=<". Were you getting any syntax errors?
Posted: Mon Sep 18, 2006 9:04 am
by akimm
I didn't recieve syntax error, however, I didn't recieve anything lol. It just came up blank.
Posted: Mon Sep 18, 2006 9:16 am
by kaszu
You had to turn on error_reporting & display_errors, that's why you were receiving blank page
http://uk.php.net/manual/en/ref.errorfunc.php
I made some changes
Posted: Mon Sep 18, 2006 9:31 am
by akimm
I made your suggested changes, then made my own. It now does print what its supposed to, but it will not do the comparrison that my set variables should be doing. If anyone knows what might be errorenous in this, please let me know. I am honestly in the fog.
Code: Select all
<?php
$img = "<img src=http://www.akimm.com/images/new1.gif>";
$file = "journal06/journal/journalaug_sept.txt";
$befor2 = fileatime($file)/3600/24 <= 2;
$roundmok = round(time());
$muk = "sorry, no new journals, click " . "<A HREF=HTTP://WWW.AKIMM.COM/JOURNAL06/JOURNAL.PHP>" . " here" . "</A>" . "to view older entrys";
if(file_exists($file)) {
if($roundmok - $befor2) {
echo $img . "<a href=http://www.akimm.com/journal06/journal.php>" . "Click to view new journal entrys " . "</a>";
} else {
echo $muk;
}
}
?>
Well..
Posted: Mon Sep 18, 2006 9:33 am
by akimm
Can you please tell me the mistake? You see my webbie is not my server YET. I'm yet to learn that stuff throroughly enough to run a server.
Thanks for pointing out my mistake, but please tell me where the mistake is, then i can get this stuff off the ground.
Posted: Mon Sep 18, 2006 9:56 am
by kaszu
I just can't understand what you are comparing, because
Code: Select all
$befor2 = fileatime($file)/3600/24 <= 2; //This will be a boolean (false?)
$roundmok = round(time()); //This will be a timestamp, can't see the need for round function here
And what this should do? If i'm not wrong, then it will be executed everytime.
Sorry, my English is not soo good as i would want it to be, so probably i missed something, but when exactly condition should be true?
Posted: Mon Sep 18, 2006 9:58 am
by twigletmac
Instead of:
Code: Select all
$befor2 = fileatime($file)/3600/24 <= 2;
try
Code: Select all
$befor2 = fileatime($file)/3600/24;
and then instead of
try
The comparison needs to take place in the if statement.
Mac
Posted: Mon Sep 18, 2006 11:49 am
by kaszu
fileatime(...) and time() returns Unix timestamp (in seconds), if i understand correctly, then instead of
should be
or isn't it?
Sorry, i just can't stop thinking about it!
yes..
Posted: Mon Sep 18, 2006 1:23 pm
by akimm
kaszu- thank you for the final fix, that was what needed done after I made twigletmac's suggestions. Thank you both very much, I knew I had it generally right, but this would of taken me a far greater time without your help. I do appreciate that much.