Need experts opinion.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Need experts opinion.

Post 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>"; 
	}
   }
?>
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Code: Select all

if(file_exists($file) {
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?
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

I didn't recieve syntax error, however, I didn't recieve anything lol. It just came up blank.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post 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
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

I made some changes

Post 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;
	}
	}

?>
Last edited by akimm on Mon Sep 18, 2006 9:41 am, edited 1 time in total.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Well..

Post 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.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post 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.

Code: Select all

if($roundmok - $befor2) {
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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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

Code: Select all

if($roundmok - $befor2)
try

Code: Select all

if(($roundmok - $befor2) <= 2)
The comparison needs to take place in the if statement.

Mac
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post by kaszu »

fileatime(...) and time() returns Unix timestamp (in seconds), if i understand correctly, then instead of

Code: Select all

$roundmok = round(time());
should be

Code: Select all

$roundmok = time()/3600/24;
or isn't it?
Sorry, i just can't stop thinking about it!
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

yes..

Post 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.
Post Reply