HELP ME!

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
xDustin
Forum Newbie
Posts: 4
Joined: Mon Sep 20, 2010 4:05 am

HELP ME!

Post by xDustin »

Hey, I'm needing help. I'm stuck on something..

I'm wanting to do do this..


if $x is 15 less than $y then

I don't want it to be equal or less than because I've got something that updates every 5 seconds and if it doesn't update within 15 seconds it notifys me.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: HELP ME!

Post by requinix »

So what book are you trying to learn programming from?
xDustin
Forum Newbie
Posts: 4
Joined: Mon Sep 20, 2010 4:05 am

Re: HELP ME!

Post by xDustin »

None? I'm just stumped on this part.

I'm wanting to check the "Last modified" time of a file on the server which I know how to,

but if the file hasn't been updated within "X" minutes/seconds whatever, I want it to notify me.

I know PHP, just this part is annoying me.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: HELP ME!

Post by requinix »

xDustin wrote:if $x is 15 less than $y then

Code: Select all

if ($x == $y - 15)
Surely I'm answering the wrong question.
xDustin
Forum Newbie
Posts: 4
Joined: Mon Sep 20, 2010 4:05 am

Re: HELP ME!

Post by xDustin »

Wish it was that easy, but that doesn't work.. That is only if it's exactly 15 less. I'm wanting to do 15 or more/less

I've tried $x == $y > 15 etc but doesn't work.

What I'm exactly wanting to do is...

Code: Select all

<?PHP
$last_modified = date("i", filemtime("../images/Temp.jpg")); //Minute point file was last modified
$curr_time = date("i"); //Current Minute for server.

// If $last_modified is 15 OR more minutes behind $curr_time I want it to do what I want. 
?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: HELP ME!

Post by requinix »

1. So it's actually neither the "if $x is 15 less than $y then" nor the "I'm wanting to do 15 or more/less" but
value A is no more than value B minus 15
2. Using date("i") is close but not what you want to be doing.

Code: Select all

<?PHP
$last_modified = filemtime("../images/Temp.jpg"); //Time file was last modified
$curr_time = time(); //Current Time for server.

// If $last_modified is 15 OR more minutes behind $curr_time I want it to do what I want.
if ($last_modified <= $curr_time * 15*60) {
xDustin
Forum Newbie
Posts: 4
Joined: Mon Sep 20, 2010 4:05 am

Re: HELP ME!

Post by xDustin »

That looked promising, but it isn't working.

I've came up with a solution using the date() function, it works.

Code: Select all

<?php
$last_modified = date("i", filemtime("../images/Temp.jpg")); //Minute point file was last modified
$curr_time = date("i"); //Current Minute for server.

$diff = "";

if ($curr_time > $last_modified){
$diff = $curr_time - $last_modified;
}else if($last_modified > $curr_time){
$diff = $last_modified - $curr_time;
}

if ($diff > 5){
echo "Needs updated";
}else{
echo "Already updated";
}
?>
Post Reply