Page 1 of 1

Suggestion how to Check for action

Posted: Fri Sep 09, 2011 6:54 pm
by nite4000
Hey everyone I dont think the title is a good one but I need some suggestions how to do something. I have the general idea but the date thing is what I am not sure about.

I have 3 options

Day - 1
Week - 7
Month - 30

Now on my script I want to limit a action to that many days.

Ex say they request a withdrawal well I have the limit at week(7) so their for they can only do this one time per 7 days and same with day and month now my question is..

Would I just have it check the date against the past 7 days or future? I am thinking past but just need to have all my facts before I attempt this.

If anyone can help me out that would be great.

if you need more details let me know

Thanks

Re: Suggestion how to Check for action

Posted: Fri Sep 09, 2011 10:04 pm
by flying_circus
I would probably use a timestamp.

Code: Select all

<?php
  #Variables
    $day = 86400  // Number of seconds in 1 day
   $week = 604800 // Number of seconds in 7 days
   $month = 2592000 // Number of seconds in 30 days

  #Check Window of Opportunity
    if($last_withdrawl > now() - $day) {
    # A day has not passed since last withdrawl
    } else {
    # More than a day has passed since the last withdrawl
    }

?>

Re: Suggestion how to Check for action

Posted: Sat Sep 10, 2011 10:54 am
by nite4000
Thanks for the reply.

the variable $last_withdrawal would be like the date of the last withdrawal correct?

Thanks

Re: Suggestion how to Check for action

Posted: Sat Sep 10, 2011 3:50 pm
by flying_circus
nite4000 wrote:Thanks for the reply.

the variable $last_withdrawal would be like the date of the last withdrawal correct?

Thanks
Exactly.

Store it as a timestamp in a database, or whatever you are using to keep track of withdrawl history.

Re: Suggestion how to Check for action

Posted: Sat Sep 10, 2011 3:53 pm
by nite4000
Thats what I thought but I like to double check sometimes.

I am actually have trouble getting it to say todays date as a time stamp in the database its comming up 0000-00-00 00-00-00


Thanks
Don

Re: Suggestion how to Check for action

Posted: Sat Sep 10, 2011 4:09 pm
by flying_circus
nite4000 wrote:Thats what I thought but I like to double check sometimes.

I am actually have trouble getting it to say todays date as a time stamp in the database its comming up 0000-00-00 00-00-00


Thanks
Don
Don, I use the database field type integer (length 10). In php you can use the time() function to grab the current timestamp.

So, your withdrawl function might look like:

Code: Select all

<?php
  function withdrawl($user_id)
  {
  # Get Current Timestamp
    $time = time();
    
  # Update the database with the current timestamp of the withdrawl:
    $query = "UPDATE `users` SET `last_withdrawl`='{$time}' WHERE `user_id`='{$user_id}' LIMIT 1";
    
    // .. your code here .. //
  }
?>
If you want to convert the timestamp back into a human readable format, you can do so easily with the date() function:
print "Human Friendly Data: " . date('F d, Y', $last_withdrawl);


Another option is to use mysql's (I assume you are using mysql, if not, your database *should* offer similar functionality) unix timestamp features. You can check them out here:
http://dev.mysql.com/doc/refman/5.5/en/ ... -timestamp

Re: Suggestion how to Check for action

Posted: Sat Sep 10, 2011 4:24 pm
by nite4000
hey this is what i got


got the saving to db working right

but here is my code and I will explain to you can follow

Code: Select all

if($f_settings['en_co_limit']=="1") //check to see if the cashout feature is enabled
  {
	
	  if($f_settings['limitperiod']=='1')//1 means day
	  {
		 
  		$day = 86400;  // Number of seconds in 1 day
 
	   		 if($wdcount['request'] > $time - $day) { //subtract the last recorded time from the day
			
					 if ($wd_count >= $f_settings['co_limit']) { // check the number of time that are found against the limit
			
					$query=mysql_query("Select count(*) from withdrawal_count WHERE username ='{$_SESSION['m_user']}'")or die(mysql_query());
			  		list($wd_count) = mysql_fetch_row(mysql_query($query));
		 		    $error = TRUE;
				    $msg .= 'Opps! You are only allowed '.$f_settings['co_limit'].' cashout request per day';
					
					}
		 	}
			
     }
	 
	 
}



I think i have something backwards and its not giving the error msg like it should.
any suggestions what to correct?

Don

Re: Suggestion how to Check for action

Posted: Sun Sep 11, 2011 1:20 pm
by flying_circus
I got a little turned around in your code, it looked like you were trying to reference $wd_count before you created it. I am not sure I completely understand what the code is supposed to do, but I have cleaned it up and hopefully between this and what you have, you can make it work for your needs.

Code: Select all

<?php
  function withdrawal_count($user_id, $period)
  {
  # Define Time: Now
    $time = time();
    
  # Count Number of User Withdrawals Within Last Period
    $query = sprintf("SELECT count(*) FROM `withdrawal_count` WHERE `username` ='%s' AND UNIX_TIMESTAMP(`withdrawal_time`) > '%d' LIMIT 1;",
                     mysql_real_escape_string($user_id),
                     mysql_real_escape_string($time - $period));
                                 
  # Fetch Records
    list($wd_count) = mysql_fetch_row(mysql_query($query));
    
    return $wd_count;
  }
  
  
  
  
  if($f_settings['en_co_limit']=="1") { // check to see if the cashout feature is enabled
  # If Limit Period Exists, Check Withdrawal Count Within Period
    if(isset($f_settings['limitperiod'])) {
      switch($f_settings['limitperiod']) {
        case '1':
          $period_name = "Day";
          $withdrawal_count = withdrawal_count($_SESSION['m_user'], 86400);
          break;
        case '7':
          $period_name = "Week";
          $withdrawal_count = withdrawal_count($_SESSION['m_user'], 604800);  
          break;
        case '30':
          $period_name = "Month";
          $withdrawal_count = withdrawal_count($_SESSION['m_user'], 2592000);
          break;
      }
    }
    
  # If Withdrawal Count Is Greater Than 0, User Has Made a Withdrawal Within The Specified Period, Deny
    if($withdrawal_count > 0) {
      $error = TRUE;
      $msg .= "Opps! You are only allowed {$f_settings['co_limit']} cashout request per {$period_name}";
    }
  }
?>

Re: Suggestion how to Check for action

Posted: Sun Sep 11, 2011 1:59 pm
by nite4000
hey thanks for the reply and sorry for the confusion. I tried ya code however i am getting errors.

Here is what I am trying to do exactly

i have a option in admin panel that enables the limit system for the withdrawals

if enabled the admin can set the number of times say 2 which is the co_limit and then set the limitperiod which is 1,7,30 which is day,week,month

from there it would limit how many times a use can input a withdrawal within that time frame.

I did put this code inside a if POST since its a form so is that ok?

i have the limit set at 2 but yet i have done it more then 2 times.. I also thought about just having the form hidden until the time expired and they can request a cashout again but not sure if that would be good idea or not


i hope i will get this working soon thanks
Don