Solved

advanced time question.

Posted on 2004-10-05
8
227 Views
Last Modified: 2008-02-01
Hi i need som kind of function to do my work. In my mysqltable i have a date ex 2004-10-05 14:00 and i need to check if it have gone ex 24hour. If you read my code i have post here you will propobly understand what i mean. And if it have gone more then 24h the script will not stop at
} if ($elapsed < $wait) {
            bterror("Not authorized (" . ($wait - $elapsed) . "h) - READ THE FAQ!");
            exit();
      }
I hope someone can help me with this question. I think it's kind a hard.



function ratiocheck()
{
      global $_GET;
      
      $ratio = 0.1;
      $gigs = 1;

      $hash = checkhash($_GET['info_hash']);
      
      $result = mysql_query("SELECT * FROM torrents WHERE p_hash = '$hash'")OR die (bterror("error in mysql"));
      while ($gtim = mysql_fetch_array($result))
      {
            $p_time = $gtim['p_time'];
         // $p_time is the time (2004-10-05 16:00)
      }
      
      $p_time = $elapsed;
      // ratio
      if ($ratio < 0.5) {
            $wait = 24;
      } elseif ($ratio < 0.8 || $gigs < 6) {
            $wait = 12;
      } elseif ($ratio < 0.9 || $gigs < 10) {
            $wait = 6;
      } elseif ($ratio < 1.0 || $gigs > 15) {
            $wait = 0;
      } if ($elapsed < $wait) {
            bterror("Not authorized (" . ($wait - $elapsed) . "h) - READ THE FAQ!");
            exit();
      }
}
//############################# SLUT #######################
0
Comment
Question by:stromberg10
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 50 total points
ID: 12229068
You are not setting the $elapsed variable anywhere.  Maybe this line:

$p_time = $elapsed;

Should be this:

$elapsed = $p_time;

Or, you could remove the line altogether, and then make the final if statement look like this:

if ($p_time < $wait) {
          bterror("Not authorized (" . ($wait - $p_time) . "h) - READ THE FAQ!");
          exit();
}


Any reason you're screaming SLUT at the bottom of the code?
0
 
LVL 27

Assisted Solution

by:Diablo84
Diablo84 earned 50 total points
ID: 12230927
As a side note you do not need this line

global $_GET;

$_GET is a super global, you can access it in the function anyway
0
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 50 total points
ID: 12231993
You could use strtotime() to change the '2004-01-01 10:10' into a unix timestamp. You could then match this with the result from mktime() and look if the 24 hours have past:

if(mktime() < strtotime($p_date)  + $wait)
{
  //still in waiting periode
}
else
{
  //waiting period has passed.
}

Or I might understand your question incorrectly.

Regards

-r-
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 1

Assisted Solution

by:aot2002
aot2002 earned 50 total points
ID: 12233871
mysql> SELECT DATE_ADD('1999-01-01', INTERVAL 1 DAY);
        -> '1999-01-02'



http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html
0
 
LVL 14

Assisted Solution

by:ThG
ThG earned 50 total points
ID: 12238396

I think Roonan's answer should work. If you want a MySQL solution here it is:

mysql> select if(now() > date_add('2004-10-03 13:22:00', INTERVAL 1 DAY), 1, 0);

     $result = mysql_query("SELECT *,IF(NOW() > date_add(p_time, INTERVAL 1 DAY), 1, 0) AS elapsed FROM torrents WHERE p_hash = '$hash'")OR die (bterror("error in mysql"));
          $p_time = $gtim['p_time'];
        // $p_time is the time (2004-10-05 16:00)
        $elapsed = $gtim['elapsed'];
         // $elapsed is 1 if 24 hours elapsed, otherwise 0
     }
     
   
0
 
LVL 1

Expert Comment

by:aot2002
ID: 12238685
thanks ThG

i just wanted to make sure he had both options !
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question