Solved

advanced time question.

Posted on 2004-10-05
8
229 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

623 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