Jump to content

DeanWhitehouse

Members
  • Posts

    2,527
  • Joined

  • Last visited

Everything posted by DeanWhitehouse

  1. Seems to be working now, after a bit of changing around
  2. Hmm that is true, i changed it but still no luck
  3. Yes, this is the wrong forum, IE has always been known to cause problems with websites.
  4. Hmm i am worried if this function works. I am trying this $time_dif = FormatTimeDiff(strtotime($next_maturation),strtotime(date("Y-m-d H:i:s"))); print_r($time_dif); And it shows Array ( [y] => 0 [f] => 0 [w] => 0 [d] => 0 [h] => -5 [m] => -58 [s] => -20 ) Yet the next maturation should of been 3 minutes ago, and therefore updated. Let me explain in brief what i want to do. I need to add interest at every maturation, for example if the maturation is one day add it every day, now as i don't know how i would use a cron job i am putting it in the page code. I am checking to see if the next maturation is equal to or less than today and if so then update the db. This is the relevant code <?php if(isset($_GET['account'])) { $id = mysql_real_escape_string(((int) $_GET['account'])); $sql = "SELECT interest,name,maturation FROM nbanking_types WHERE id = '".$id."'"; $sql = mysql_query($sql); if(mysql_num_rows($sql) == 0) { echo "Account type Not Found"; } else { $account = mysql_fetch_assoc($sql); $sql = "SELECT last_maturation,balance FROM user_nbanking WHERE user_id = '".mysql_real_escape_string($_SESSION['user_id'])."' AND package_id = '".$id."'"; $sql = mysql_query($sql); if(mysql_num_rows($sql) == 0) { mysql_query("INSERT INTO user_nbanking (user_id,package_id) VALUES ('".mysql_real_escape_string($_SESSION['user_id'])."','".$id."')"); $sql = mysql_query($sql); } $user_account = mysql_fetch_assoc($sql); $next_maturation = date("Y-m-d H:i:s",strtotime($user_account['last_maturation']." + ".$account['maturation']." days"));//Next maturation date if($next_maturation <= date("Y-m-d")) { mysql_query("UPDATE user_nbanking SET balance = '".($user_account['balance'] + ($user_account['balance'] / 100 * $account['interest']))."', last_maturation = NOW() WHERE WHERE user_id = '".mysql_real_escape_string($_SESSION['user_id'])."' AND package_id = '".$id."'") or die(mysql_error()); $sql = mysql_query($sql); $user_account = mysql_fetch_assoc($sql); $next_maturation = date("Y-m-d H:i:s",strtotime($user_account['last_maturation']." + ".$account['maturation']." days"));//Next maturation date } $time_dif = FormatTimeDiff(strtotime($next_maturation),strtotime(date("Y-m-d H:i:s"))); print_r($time_dif); $new_time = ""; if($time_dif['y'] < 0) $new_time .= " ".$time_dif['y'].($time_dif['y'] < 1 ? " years" : " year"); if($time_dif['f'] < 0) $new_time .= " ".$time_dif['f'].($time_dif['f'] < 1 ? " months" : " month"); if($time_dif['w'] < 0) $new_time .= " ".$time_dif['w'].($time_dif['w'] < 1 ? " weeks" : " week"); if($time_dif['f'] < 0) $new_time .= " ".$time_dif['f'].($time_dif['f'] < 1 ? " months" : " month"); if($time_dif['d'] < 0) $new_time .= " ".$time_dif['d'].($time_dif['d'] < 1 ? " days" : " day"); if($time_dif['h'] < 0) $new_time .= " ".$time_dif['h'].($time_dif['h'] < 1 ? " hours" : " hour"); if($time_dif['m'] < 0) $new_time .= " ".$time_dif['m'].($time_dif['m'] < 1 ? " minutes" : " minute"); if($time_dif['s'] < 0) $new_time .= " ".$time_dif['s'].($time_dif['s'] < 1 ? " seconds" : " second"); $new_time = str_replace("-","",$new_time); For argument and testing sake i put the maturation period at one day and set my last maturation yesterday at 18:25 uk time, it is now 18:32 uk time.
  5. omg, sorry , i was being blond in my logic i was trying to get the amount of time until the next date, but was instead coding it to get the difference between the wrong dates Thanks for the help
  6. <?php if($_SERVER['HTTP_REFERER']) { $aff_array = array("http://www.RANDOMWEBSITE1.COM", "http://RANDOMWEBSITE2.COM", "http://RANDOMWEBSITE3.COM"); shuffle($aff_array); //to make it slightly more random header("Location: ".$aff_array[rand(0,2)]);//0,2 because array keys start at 0 exit(); ?> should be <?php if($_SERVER['HTTP_REFERER']) { $aff_array = array("http://www.RANDOMWEBSITE1.COM", "http://RANDOMWEBSITE2.COM", "http://RANDOMWEBSITE3.COM"); shuffle($aff_array); //to make it slightly more random header("Location: ".$aff_array[rand(0,2)]);//0,2 because array keys start at 0 exit(); } ?>
  7. But that will mean if they visit your site and go to another one of your sites pages then back to this one they will be redirected randomly
  8. First off code <?php function FormatTimeDiff($t1,$t2 = null,$format = 'yfwdhms') { $t2 = $t2 === null ? time() : $t2; $s = abs($t2 - $t1); $sign = $t2 > $t1 ? 1 : -1; $out = array(); $left = $s; $format = array_unique(str_split(preg_replace('`[^yfwdhms]`', '', strtolower($format)))); $format_count = count($format); $a = array('y'=>31556926, 'f'=>2629744, 'w'=>604800, 'd'=>86400, 'h'=>3600, 'm'=>60, 's'=>1); $i = 0; foreach($a as $k=>$v) { if(in_array($k, $format)) { ++$i; if($i != $format_count) { $out[$k] = $sign * (int)($left / $v); $left = $left % $v; } else { $out[$k] = $sign * ($left / $v); } } else { $out[$k] = 0; } } return $out; } if(isset($_GET['account'])) { $id = mysql_real_escape_string(((int) $_GET['account'])); $sql = "SELECT interest,name,maturation FROM nbanking_types WHERE id = '".$id."'"; $sql = mysql_query($sql); if(mysql_num_rows($sql) == 0) { echo "Account type Not Found"; } else { $account = mysql_fetch_assoc($sql); $sql = "SELECT last_maturation,balance FROM user_nbanking WHERE user_id = '".mysql_real_escape_string($_SESSION['user_id'])."' AND package_id = '".$id."'"; $sql = mysql_query($sql); if(mysql_num_rows($sql) == 0) { mysql_query("INSERT INTO user_nbanking (user_id,package_id) VALUES ('".mysql_real_escape_string($_SESSION['user_id'])."','".$id."')"); $sql = mysql_query($sql); } $user_account = mysql_fetch_assoc($sql); $next_maturation = date("Y-m-d H:i:s",strtotime($user_account['last_maturation']." + ".$account['maturation']." days"));//Next maturation date if($next_maturation <= date("Y-m-d")) { mysql_query("UPDATE user_nbanking SET balance = '".($user_account['balance'] + ($user_account['balance'] / 100 * $account['interest']))."', last_maturation = NOW() WHERE WHERE user_id = '".mysql_real_escape_string($_SESSION['user_id'])."' AND package_id = '".$id."'") or die(mysql_error()); $sql = mysql_query($sql); $user_account = mysql_fetch_assoc($sql); $next_maturation = date("Y-m-d H:i:s",strtotime($user_account['last_maturation']." + ".$account['maturation']." days"));//Next maturation date } $time_dif = FormatTimeDiff(strtotime($user_account['last_maturation']),strtotime($next_maturation)); $new_time = ""; if($time_dif['y'] > 0) $new_time .= " ".$time_dif['y'].($time_dif['y'] > 1 ? " years" : " year"); if($time_dif['f'] > 0) $new_time .= " ".$time_dif['f'].($time_dif['f'] > 1 ? " months" : " month"); if($time_dif['w'] > 0) $new_time .= " ".$time_dif['w'].($time_dif['w'] > 1 ? " weeks" : " week"); if($time_dif['f'] > 0) $new_time .= " ".$time_dif['f'].($time_dif['f'] > 1 ? " months" : " month"); if($time_dif['d'] > 0) $new_time .= " ".$time_dif['d'].($time_dif['d'] > 1 ? " days" : " day"); if($time_dif['h'] > 0) $new_time .= " ".$time_dif['h'].($time_dif['h'] > 1 ? " hours" : " hour"); if($time_dif['m'] > 0) $new_time .= " ".$time_dif['m'].($time_dif['m'] > 1 ? " minutes" : " minute"); if($time_dif['s'] > 0) $new_time .= " ".$time_dif['s'].($time_dif['s'] > 1 ? " seconds" : " second"); } ?> Quick sum up of the code, the above code should get certain user account details from their account and work out when they are due to be added interest to their balance and if they are add it and set the last paid day to this day. Now i know for a fact that the code is flawed (although only one way) and that is that if the user doesn't log in for a few days then they will have gaps between interest payment. What ways would you recommend around this without cron jobs. Also i think the script is bugged in its logic. One other thing i tried making the day between the interest payments 0 and i didn't gain a payment, can anyone see why. I am tired so i might of missed things, i just need another head to work on this edit: sql dumps This is the nbanking_types table (a row in it) id interest maturation name 1 17.5 1 High Interest and this is the user banking one User Id Package ID Balance ID Last Maturation 2 1 50 1 2009-01-28 18:07:54 Thanks, Blade
  9. Oops i missed out a bit should of been <?php $aff_array = array("http://www.RANDOMSITE1.COM", "http://RANDOMSITE2.COM", "http://RANDOMSITE3.COM"); shuffle($aff_array); //to make it slightly more random header("Location: ".$aff_array[rand(0,2)]);//0,2 because array keys start at 0 exit(); ?>
  10. What is this supposed to achieve? if($_SERVER['HTTP_REFERER']) { also try <?php $aff_array = array("http://www.RANDOMSITE1.COM", "http://RANDOMSITE2.COM", "http://RANDOMSITE3.COM"); shuffle($aff_array); //to make it slightly more random header("Location: ".rand(0,2));//0,2 because array keys start at 0 exit(); ?>
  11. Hmm when i do print_r( FormatTimeDiff(strtotime($user_account['last_maturation']),strtotime($next_maturation))); It says " Array ( [y] => 0 [f] => 0 [w] => 4 [d] => 2 [h] => 0 [m] => 0 [s] => 0 ) " and doesn't seem to be counting minutes hours or seconds, or did i misunderstand the functions purpose?
  12. Ok, works with strtotime (it seems) I tidied it up making it easier to read function FormatTimeDiff($t1,$t2 = null,$format = 'yfwdhms') { $t2 = $t2 === null ? time() : $t2; $s = abs($t2 - $t1); $sign = $t2 > $t1 ? 1 : -1; $out = array(); $left = $s; $format = array_unique(str_split(preg_replace('`[^yfwdhms]`', '', strtolower($format)))); $format_count = count($format); $a = array('y'=>31556926, 'f'=>2629744, 'w'=>604800, 'd'=>86400, 'h'=>3600, 'm'=>60, 's'=>1); $i = 0; foreach($a as $k=>$v) { if(in_array($k, $format)) { ++$i; if($i != $format_count) { $out[$k] = $sign * (int)($left / $v); $left = $left % $v; } else { $out[$k] = $sign * ($left / $v); } } else { $out[$k] = 0; } } return $out; }
  13. How would i do it with mysql ? Or with that function you found rhodesa it doesn't say how the time should be formatted, just strtotime?
  14. How can i find out the time until the next event, example The last event was 29 - 01 - 2009 (stored as a mysql timestamp) and the next event is that timestamp plus a certain amount of days, i can get the date of the next event but what i want to get is the amount of time before the next date in days, then using that work out if it is in minutes hours etc. So if the next event was in four hours it would say four hours not 0 days, but if the event was tomorrow it would say one day, etc. This is my code so far (relevant part) $next_maturation = date("d - m - Y",strtotime($account['maturation']." days +".$user_account['last_maturation']));//Next maturation date echo $next_maturation - date("d - m- Y",strtotime("- ".$account['maturation']));//not working :s says - 4
  15. change $result = @mssql_query($query) or die ('Die'); to $result = mssql_query($query) or die ('Died, ahh, here is why <br>'.mssql_error()); not 100% on the mssql error bit
  16. Try $newtext = wordwrap($text, 20, "<br />\n",true);
  17. Can you show us the code which generated the error,
  18. To save time, and coding you could just give the inputs a name like name="questions[]" Which will automatically put it in an array
  19. I don't see why you changed it after we showed you the correct way :s
  20. Just rereading mine it seems it is very flawed, lol, i started writing it but didn't want to copy gn1s' one
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.