Jump to content

zero_ZX

Members
  • Posts

    223
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

zero_ZX's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. So, after reviewing my code, it would appear that a variable was misspelled which is why the chance of winning was a set 30%..
  2. Hi, I basically want a function that takes a parameter which is a percentage chance of the functioning returning true. A user can move from tier 1->10 and at tier 1 there's a 70% chance to move to tier 2, from tier 2 there's a slightly less chance to move up, and so on. I tried with the following piece of code: public function rollTheDice($winnerPercentage) { $number = rand(1, 100); if ($number <= $winnerPercentage) return true; return false; } The above code makes logical sense to me: 1. Pick a random number between 1 and 100. 2. If that number is less than or equal to the percentage, then we passed (example, if the random number is less than or equal to 70.. there must be a 70% chance of this?) This however does not seem to work, in fact it appears that when simulating a roll, 70% fails at the very first step (where there is a 70% chance of winning..) To actually make it to tier 10, has yet to be accomplished, so by simulating this with unlimited attempts for 120 seconds straight doesn't seem to "win". I tried (just for fun) and change the if-statement so: if ($number >= $winnerPercentage) This seems to be working quite well, as the simulator quickly reaches tier 10 this way. Any suggestions to code changes, or can someone explain why it is working way better when exchanging less than with greater than?
  3. Hi, sorry about that, you made the correct assumption <title> '.$lang['PAGE_TITLE'].'</title> I thought the lang array was actually global as it's not in any function, would I need to declare the $lang variable global?
  4. I actually ran into some new issues. It appears that I cannot use the variables that I have now included. From my portolio.php I include the header.php <?PHP require_once("../../inc/common.inc.php"); require_once("inc/header.php"); DisplayHeader(); ?> From the header.php I include the main.php <?php //require_once("../inc/common.inc.php"); require_once("lang/main.php"); /** * Created by JetBrains PhpStorm. * User: Mikkel * Date: 05-08-13 * Time: 12:07 * To change this template use File | Settings | File Templates. */ function DisplayHeader(){ //.... } From the main.php I include a single language file: <?php //session_start(); //header('Cache-control: private'); // IE 6 FIX if(isSet($_GET['lang'])) { $lang = $_GET['lang']; // register the session and set the cookie // $_SESSION['lang'] = $lang; setcookie('lang', $lang, time() + (3600 * 24 * 30)); } //else if(isSet($_SESSION['lang'])) //{ // $lang = $_SESSION['lang']; //} else if(isSet($_COOKIE['lang'])) { $lang = $_COOKIE['lang']; } else { $lang = 'en'; } switch ($lang) { case 'en': $lang_file = 'en.php'; break; case 'da': $lang_file = 'da.php'; break; default: $lang_file = 'en.php'; } require_once ("lang/".$lang_file); ?> In which the variable $lang is set $lang = array(); $lang['PAGE_TITLE'] = 'My website page title'; Yet I receive this message: [Thu Aug 22 13:06:27 2013] [error] [client 83.92.74.170] PHP Notice: Undefined variable: lang in /home/thomsen/mikkel/inc/header.php on line 26,
  5. Hi kicken, Thanks a lot for you in-depth answer. It really helped me understand the include behind-the-scene - and solved my problem.I ended up using the common.inc as you did.
  6. So, depending on where I include the header from, I would need different paths for including the lang file? If so is there any alternative? I will be using different paths multiple times.
  7. Hi, I'm having issues with included files within included files. This is my project: I browse my portfolio.php and I receive this error: [Wed Aug 21 19:50:01 2013] [error] [client 83.92.74.170] PHP Fatal error: require_once() [<a href='function.require'>function.require</a>]: Failed opening required '/home/thomsen/mikkel/html/portfolio/lang/main.php' (include_path='.:/usr/share/pear/') in /home/thomsen/mikkel/inc/header.php on line 3, referer: http://www.mikkel.thomsen.im/ In my portfolio.php I have: <?PHP require_once("../../inc/header.php"); $title = "Test"; ?> In my header.php I have: <?php require_once("../lang/main.php"); I don't know why it cannot get this file as I move up to my "project", into "lang" and fetch the file, which doesn't exists for some reason. This error is not caused by file permissions. Thanks in advance
  8. Hi, I'm limiting a specific action to only be possible each 12 hour. To do that I use the current time: $time = strtotime(date("Y-m-d H:i:s")); and the last time the action was done is stored just like it (but from a db). Now I'm about to compare them, but I'm curious on how to make the last_vote variable 12 hours larger. I tried with 43200 which is 12 hours in seconds, but that appeared to be very incorrect. Any help is much appreciated.
  9. Yea that would be for generating the for which i can already do. I want to describe the fields by adding a label, and it will be a mess to store labels together with the forms.
  10. No I do not have any code. The problem is not coding, more like designing.
  11. Hi, I have a class that loops through a mysql table and then auto generates a form based on the table. It can ignore fields if there should be a need of that. Any way I would like to label the different inputs, provide descriptions etc, and would like to know an approach to this. What would you do in this case? I have a matching table containing settings where i could put a field and then it could contain a serialized array with the info, but not sure if there's a better alternative, please let me know
  12. This didn't work either. In mysql (where i get last_vote) it says: 2012-04-30 20:25:37 so a datetime. Hope it doesn't matter?
  13. Hi, So I only want my users to be able to perform certain tasks each 12 hours. This is the code I use: function canVote($ip, $vote_id, $updateTimer = true){ $time = date("Y-m-d H:i:s"); $this->CI->db->where('vote_id', $vote_id); $this->CI->db->where('user_ip', $ip); $this->CI->db->from('votes_voters'); $count = $this->CI->db->count_all_results(); /*$count = $this->CI->db ->where('vote_id =', $vote_id) ->where('user_ip =', $ip) ->from('votes_voters') -count_all_results();*/ $row = $this->CI->db ->where('vote_id =', $vote_id) ->where('user_ip =', $ip) ->get('votes_voters') ->row(); if($count == 0){ $data = array( 'vote_id' => $vote_id, 'user_ip' => $ip, 'last_vote' => $time ); $this->CI->db->insert('votes_voters', $data); return true; } else{ $last_vote = $row->last_vote; if($last_vote + strtotime("12 hours") < $time){ return false; } else{ if($updateTimer = true){ $data = array( 'last_vote' => $time, ); $this->CI->db->where('vote_id', $vote_id); $this->CI->db->where('user_ip', $ip); $this->CI->db->update('votes_voters', $data); } return true; } } } Apparently the failing bit is this: if($last_vote + strtotime("12 hours") < $time){ return false; } I believe you can guess what I'm trying to do here, if variable 1 + 12 hours is smaller than variable 2, then return false. Any help is much appreciated.
  14. Hi, So there have probably been loads of those questions however from what I've searched I have not been able to find the answer. So I receive this error, when using this function: function updateCart(row_id, item_qty) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("item_place").innerHTML = xmlhttp.responseText; } } xmlhttp.open("POST",'<?php echo site_url("votepoints/updateCart/");?>',true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", row_id.length); xmlhttp.setRequestHeader("Connection", "close") xmlhttp.send("row_id="+row_id+"&item_qty="+item_qty); } The problem is the row_id item_qty works fine for some reason. I guess the difference is that qty is an int, and id is a string. Right, so Before the function i decided to put var row_id = ""; to see if that fixed the problem. Apparently it didn't. I'm calling the function via a link: javascript:updateCart(e22659b1a980aaca47048bebd5523817, 2) And this string generates this error for some reason, and I have no idea why.
×
×
  • 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.