Jump to content

Monkuar

Members
  • Posts

    987
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Monkuar

  1. yep working now topic solved
  2. But that would change the user's input and it may no longer match. If the jackpot was 3|1|2 and they entered 3|1|2, changing the numerical order would make it 1|2|3 and thus not a match. $numbers = "32|22|22,32|22|21"; $numArray2 = array_unique(explode("|", $numbers)); if(count($numArray2)<3) { $std->Error2("You cannot pick 2 numbers with the same ticket"); }else{ echo "not working ?"; exit; } I think the array_unique reads the code wrong with the comma.... cuz that should show the error, because the first Array is 32|22|22 no idea? I always have problems
  3. Well if the jackpot numbers were 3|5|8, if someone chose 8|3|5, they wouldn't win anyway? i used some different code that you made me a couple days ago, because quite frankly it was just to much to handle , Ben made me some new code which i modified a little, which is: $query = $DB->query("SELECT l.*,m.name,m.id FROM ibf_lottery_tickets l LEFT JOIN ibf_members m ON (m.id=l.memberid) WHERE l.lotteryid='{$lotto['i_id']}' ORDER BY time_bought DESC"); while($ticket2 = $DB->fetch_row($query)) { //Check Exact winnings/Jackpot $numbers_chosen = "2|5|1,20|2|5"; $winning_numbers = "2|5|1"; // Let's get those winning numbers into an array $jackpot = explode('|', $winning_numbers); $tiers_won = array(); $tickets = explode(',', $numbers_chosen); foreach ($tickets as $ticket) { $balls = explode('|', $ticket); if ($balls == $jackpot) { // All three balls match the jackpot (in the right order too) $tiers_won[] = 100; $jackpotwon = True; $jackpotamount = "{$ticket2['name']}"; $numbersthatwonjackpot = "{$balls['0']}|{$balls['1']}|{$balls['2']}"; $nameinfo = "{$ticket2['id']}|{$ticket2['name']}|{$ticket2['star']}"; } elseif ( ! array_diff($balls, $jackpot)) { // All the balls are the same but not necessarily in the correct order. $tiers_won[] = 30; } elseif ($balls[0] == $jackpot[0] AND $balls[1] == $jackpot[1]) { // The first two balls match those of the jackpot $tiers_won[] = 20; } elseif (count(array_diff($balls, $jackpot)) == 1) { // Only one ball is a mismatch (not considering the order) $tiers_won[] = 5; } } if ($jackpotwon){ //I run my queries here to for $nameinfo <br>$numbersthatwonjackpot/etc to give them the amount of gold in the jackpot } That code above pulls my data for each users ticket And I sort it by DESC and date so whoever chose that jackpot number FIRST is actually going to win first, (I don't know how to make it so the 2nd jackpot winner could win also) (Maybe in the future?) The code for this topic is because, I used this to generate my winning jackpot number: function choose_numbers($number,$max) { global $ibforums,$std; $array = array(); $i = 0; while($i != $number) { $rand = mt_rand(1,$max); if(!in_array($rand,$array)) { $array[] = $rand; $i++; } } return $array; That will never EVER display 2 of the same numbers, (I hope not 3 either), so that is why I need to check the user input and not let them tamper my data to try to edit the post data and make all there balls the same, which the code works fine that you provided, Thanks ^^ As of right now, it's working correctly and I am going to be ditching the cron job I could just store my function to re-run the lottery on the main index on my forum, so it will be refreshed all the time while people browse on my forum, and if that condition is true, it will re-update the lottery, that code is actually here: $end_date = $lotto['start_time'] +$lotto['run_for']; if($end_date < time() and $lotto['type'] == 'exact') { $newnumbers = $this->choose_numbers(3,36); $this->drawn_lotto++; //$wn = implode("|",$lotto['correct_balls']); //$winning_numbers = explode("|", $lotto['correct_balls']); //echo "im about to get a new lottery going"; //exit; $lp = time(); $temp = $DB->query("UPDATE ibf_lottery_lotterys SET correct_balls='{$newnumbers['0']}|{$newnumbers['1']}|{$newnumbers['2']}',start_time='$lp',run_for='3600',jackpot='',lastticket='' WHERE i_id='{$lotto['i_id']}' LIMIT 1"); //Truncate db delete everyones tickets $DB->query("TRUNCATE TABLE ibf_lottery_tickets"); } This essentially just will update the lottery and remove all the tickets.. But I will have to store the $lotto's start time and run for into a mysql field that will be run with each refresh, like just put it in a array on my board forum statistics or something, so it can be called
  4. am I missing anymore input attacks to pass not having 2 of the same balls? $numbers = "19|20|19"; $numArray = explode("|", $numbers); if ($numArray['0'] == $numArray['1'] OR $numArray['0'] == $numArray['2'] ){ $std->Error2("You cannot pick 2 numbers with the same ticket"); } The if function will see if 19 = 20, or 19 = 20 then I would it need to do $numArray['1'] == $numArray['2'] and so on right to get all possible ways? If so, is there a easier way instead of just using all OR Statements and not manually thinking about what possible way, isn't there just a way to check if 2 arrays are the same? (or 3)
  5. if(!in_array($rand,$array)) { $array[] = $rand; $i++; } Marked as Resolved. Kudos.
  6. 1 Problem sometimes it displays 1 missing number as a blank? "17|29|"
  7. srand( (double)microtime() * 1000000 ); $array = array(); $i = 0; while($i!=$number) { $array[] = mt_rand(1,$max); $i++; } return $array; is that function sorryi couldn't edit my post?
  8. function choose_numbers($number,$max) { global $ibforums,$std; srand( (double)microtime() * 1000000 ); $array = array(); $i = 0; while($i!=$number) { $array[] = mt_rand(1,$max); $i++; } $c = count($array); while($c != $number) { $array[] = mt_rand(1,$max); $c = count($array); if($c == $number) { $array = array_unique($array); $c = count($array); } } return $array; } $newnumbers = $this->choose_numbers(3,36); echo "{$newnumbers['0']}|{$newnumbers['1']}|{$newnumbers['2']}"; This echo's out my lottery balls 0|32|22 or technically RANDNuMbER|RANDNUMBER|RANDNUMBER up to 36 is the highest number. Now my issue is, I don't want 2 numbers of the same Value, EVER. Sometimes it does 2|3|2 which is BAD (for my lottery system) is there anyway I can make it so it never will echo out 2 (OR 3) of the same number?
  9. lol =], it's really just a personal preference, I really don't even know if you'll see drastic speed increase to be honest, but I do cuz it makes me feel like all my .php's are tight and super clean before i load them to the live server a Weird fetish
  10. That error means your admin disabled mysql connections to your node/server
  11. Big companys that have thousands of visitors, will use a PHP minify tool on there .php's and save backup's of the old .php's (NOT compressed) for editing purposes. Like Pshyso said, it only depends how big your site is, if you wan tto see performance. If you're running a high volume website, the best bet would backup a copy of your .php (so easy to read) and make a minified version to put it on the live server. then if u need to edit, just go back re minify when you're done. Problem Solved.
  12. Update: $numbers_chosen = "{$ticket['numbers_chosed']}"; $winning_numbers = "{$lotto['correct_balls']}"; // Let's get those winning numbers into an array $jackpot = explode('|', $winning_numbers); $tiers_won = array(); $tickets = explode(',', $numbers_chosen); foreach ($tickets as $ticket) { $balls = explode('|', $ticket); if ($balls == $jackpot) { // All three balls match the jackpot (in the right order too) $tiers_won[] = 100; $jackpotwon = True; $numbersthatwonjackpot = "{$balls['0']}|{$balls['1']}|{$balls['2']}"; $userthatone = $ticket['name']; } elseif ( ! array_diff($balls, $jackpot)) { // All the balls are the same but not necessarily in the correct order. $tiers_won[] = 30; } elseif ($balls[0] == $jackpot[0] AND $balls[1] == $jackpot[1]) { // The first two balls match those of the jackpot $tiers_won[] = 20; } elseif (count(array_diff($balls, $jackpot)) == 1) { // Only one ball is a mismatch (not considering the order) $tiers_won[] = 5; } } if ($tiers_won) { foreach ($tiers_won as $tier) { echo "User won $tier% of the winnings with one of their tickets <br>"; } } else echo "No winning ticket for this run in ANY tiers. <br>"; As you can see I added some variables in there. $numbersthatwonjackpot = "{$balls['0']}|{$balls['1']}|{$balls['2']}"; $userthatone = $ticket['name']; The problem is, this is run in a while loop (code above) $query = $DB->query("SELECT l.*,m.name,m.id FROM ibf_lottery_tickets l LEFT JOIN ibf_members m ON (m.id=l.memberid) WHERE l.lotteryid='{$lotto['i_id']}' ORDER BY time_bought ASC"); $tickets_bought = $DB->get_num_rows(); while($ticket = $DB->fetch_row($query)) { Shouldn't $ticket['name'] pull the "name" from my ibf_members table? If so it's not, and it act's like a Array? Is this because it's in the foreach loop? If so, can you help me on getting the "name" table from the ibf_members into my $ticket['name'] field? I have a feeling multidimensional array is what I will need to use? Thank you Then I added at buttom (Which I will use to run queries to give the member gold, but this is not in any loop for obvious reasons if ($jackpotwon){ echo " $numbersthatwonjackpot Jackpot Won, User Who won the jackpot: $userthatone"; } As you can see, $userthatone echo's out a array, I need it to get the name from ibf_members from that while loop, im stumped.
  13. i'll get back to you once i got all my stuff done with this, gorgeous man. This lottery system is going to be beast. Im going to add all my queries/etc so people get the gold added to there account/ that part is very easy, thanks abunch man, appreciate it. I'll pm u my final code in a couple days if u're curious
  14. Well, Let's me see: Match all 3 numbers of next drawing in the same exact order drawn to win Jackpot. (First match found wins) 100% Jackpot Match all 3 numbers, out of order, and win 30% of the JackPot Match the first 2 numbers in order, and win 20% of the JackPot Match any 2 numbers drawn, and win 5% of the Jackpot. (get's the first match?) (all Come first, whoever purchased there ticket first, so If I have 2000 users all that have purchased balls, it will run the for loop and once a jackpot found, exit the script and reset the lottery (Which I have code for that) I am really bad at explaining, but a simpliar way to explain is The exact function works, we have that code now you guys made for me, I love it. So now my System works, it's awesome. but I think I just need to add a easier way to win the jackpot you know? Matching all 3 balls out of 36 numbers is a 1 in 1:42840 chance, that is not fair for my users, so a "loose" way, like if they matched the first 2 numbers in ORDER, win 20% of the pot. and so on, I can also modify the code too if I get a head start from you guys.
  15. //Check Exact winnings/Jackpot $winning_numbers = "3|8|18"; $numbers_chosen = "3|8|19,3|22|18,|2|18|8,|2|18|8,|2|18|8,|2|18|8"; $chosen = explode(',', $numbers_chosen); foreach($chosen as $v ) { $winner = FALSE; if(strcmp($winning_numbers, $v) === 0 ) { //User has matched all 3 Numbers! GIVE THEM JACKPOT = TRUE! $jackpot = TRUE; }else{ //User has NOT Matched any, check if they matched any 2 In a row echo "?"; } } if( $jackpot ) { echo "We have a winner"; } else { echo "No soup for you!"; } Okay, now im on to if the match failed, now check for "Loose" Winnings, match the FIRST "2" in a order, set another variable to true! Im stuck again Somehow I need to need to check if they are only matching 2 times (Should it be any number in the Ticket) or the first 2? No idea Either way would work I imagine (but only would match the first 2) then stop so I would be using strcmp again I assume o.o I think im getting closer }else if(strcmp($winning_numbers, $v) === 1 ) { //User has NOT Matched any, check if they matched any 2 In a row echo "I matched 1 <br>";
  16. Yeah it will, forever. It's just weird ben's exploded the |'s but both codes seem to work. Not to be rude, but do you think yours is a little faster then bens? Cause you don't need to explode the |'s so I assume would be better? Or the performance is so minimal it doesn't matter? Okay, I will be messing with the codes now to try to get a "Loose Match" if the user has matched "2" numbers per Ticket, the same way how this was made, but (Finds the first 2 matching in order or NOT) I am going to try to figure it out on my own then post here for help, I don't want to keep cheating myself, I will learn nothing. Then if I get stuck on it for couple hours i will post here. (User will ofcourse win less Points this way) Easier to win Thnak you PFMaBiSmAd, makes little more since now. This way is alot simpler then multidimensional arrays,
  17. Hey, was wondering, how did you pass the "|" (Pipes) through the for each? I see no explode for them, (As it's not needed?) can you explain a little bit more how the code works, I really want to learn from it now. Because you help me so much ^^ I guess it makes each , a array and checks each individual 1 for the matching winning_number variable? if true = winner = TRUE right? But how in the world is there no functions/code to help with the "|'s? or PIPES, wouldn't you have to use something to make those not get into the way? thanks behicthebuilder CODE explains it good too, Thank you See now Im confused on ben's code he exploded the |'s, why wasn't this needed on Pikachus?
  18. NP I have this to $mystring = '8|18|32,18|3|8,|3|8|18'; $findme = '8|18|3'; $pos = strpos($mystring, $findme); // Note our use of ===. Simply == would not work as expected // because the position of 'a' was the 0th (first) character. if ($pos === false) { echo "The string '$findme' was not found in the string '$mystring'"; } else { echo "The string '$findme' was found in the string '$mystring'"; echo " and exists at position $pos"; } Still returns true! haha no idea man, how the hell is it returning true when 8|18|32 DOES NOT EQUAL 8|18|3 ?? /phpowned somehow i need to get this damn thing into a matchable array?
  19. $numbers_chosen = "8|18|32,18|3|8,|3|8|18"; $winning_numbers = "8|18|3"; if( strpos($numbers_chosen, $winning_numbers) !== FALSE ) { echo "Code here to give that player the winning Lottery <br><br><br>"; } else { echo "User has no Winning Tickets, failed."; } Returns true? I changed the numbers chosen 8|18|3 to 8|18|32, should return false?
  20. This is just getting ridiculous, I blame it on myself really. These are my Balls seperated by "," each seperated , is a "Ticket" with 3 chosen balls (A Lottery system Im making) User needs to match them "IN ORDER" to win jackpot. $numbers_chosen = "8|18|3,18|3|8,|3|8|18"; $winning_numbers = "8|18|3"; How would I go about in a preg_match statement through each array (Ticket) to see if it matches "Specifically" with 8|18|3, and if there is a Match (IN ORDER) I echo out true? Here is what I am working with. if (preg_match("/8|18|3/i", "8|18|3,18|3|8,|3|8|18")) { //True echo "Code here to give that player the winning Lottery"; } else { //False echo "User has no Winning Tickets, failed."; } For some reason whenever I change it around, it does not seem to work any ideas? the /i is doing something Inappropriate to the code perhaps?
  21. Dunno if I can explain it any better man... Here I will show pictures/etc to get a better explanation since my english is poor :'( Pretty much the correct_balls somehow need to match any of the numbers_chosed field, and I need the array to return a "true" if it finds that 8|13|3 pattern inside the numbers_chosed field (shown above) Now the hard part is for me needing to securely check the input when they choose there BALLS to not select the same one ( wouldn't matter because if the function you make will return true on the first find) then the numbers_chosed could have a multiple of different 8|18|3's in it, but it only returns back true once, and when it returns back one it will run the jackpot CODE that I have to give that user (XXXX AMOUNT OF FORUM GOLD) from the jackpot(Which I will code soon, really easy just I need to add it to increment per ticket cost/etc) [More users buy tickets = higher jackpot ] I will do that once I get this out of the way. The problem I think that is confusing you and me, is that trying to find "matches" would perform a "LOOSE" way of trying to get numbers, which would make the user have a way easier chance to win forum Gold, let's just scratch that. Ultimately, I really just need it to beable to match any 2 balls out of 8|18|3 to win a small amount (so the user has feels like he's actually winning forum gold while purchasing tickets), but then if they MATCH all 3 amounts, return a different variable to True, to just run the jackpot code on that specific Member and give him all the jackpot forum Gold. This is my ultimate goal and I believe I am very close to it, I have finalized the POST DATA (securing it)/etc, now I just need help on to get the data correctly identified through arrays/such which just give me a hard time. Hope this helps. And I guess when I mean "match" it needs to be in the same x|x|x ticket (group)
  22. Hey Psycho, your code works fine. I agree with you, the problem lies in my details of explaing what exactly I am looking for and you're correct about the matches, Because what if the winning balls are 3|2|1 and let's say somone picked these balls for their Lottery ticket: 1|3|2,3|2|2,3|2|1 I guess what I need is something that will select the highest Array count out of the initial array and use it as a variable. Because then according to my numbers above, that user would win a jackpot, but not technically because he never matched the 3|2|1 , only matched the singular arrays. Again, I am sorry for not explaining myself better. I hope I did now though. To generate if 1 of my Members one a Jackpot, I would simply use a if($correct_numbers == 3) /etc/etc do ifs/elses/functions/etc/ But like I said above, would be a ghetto way to win a jackpot if that was a case, I guess I am looking to match the first highest array count. If that makes any sense, sorry for the inconvenience. Awww I feel bad now Oh nice, does that notepad2 bring up functions while u type/etc?
  23. Don't know what else to say, I am speechless you actually wrote the comments out for me that greatly helped, do you use a php design software? (I use notepad++) Should i switch to a PHP Software program does it make it easier tolearn? I will pm you the lottery page once im done editing style/etc this is just wonderful! here is a beta screenshot of it, users can choose alot of balls/tickets. I think the only security flaw I have left is if people use Tamper Data to try to insert 2|1 instead of required x|x|x 3 balls. I have security in place to protect for "is_numeric" and max > 36 = error out/etc, just 1 more security flaw I think is when people will try to tamper data and input x|x instead of the fully x|x|x or if they will try to do things like x|x|x,,x|x,x| or something, which is not matching to x|x|x,x|x|x which I will post more help on that later after college class. Thanks I dont want to sound homo but I love you EDIT: If I just use 1 Array $numbers_chosen_str = "8|18|3"; Warning: Invalid argument supplied for foreach() in C:\wamp\www\sources\lottery.php on line 74 Hmm weird. Sorry to be Picky, but how would I go about finding the highest first match first and use it in a variable out of all the arrays?
  24. Extremely sorry I must have worded it wrong. lol The $winning_numbers_str must only be like this: //### Assign the chosen numbers and winning numbers $winning_numbers_str = "8|18|3"; $numbers_chosen_str = "8|18|3,8|18|3"; Because the jackpot for the lottery is only 3 balls ( 8|18|3 ) That need to match with numbers_chosen. So essentially it's not really a "Match" as before? More of a array Match if you will instead? (Kinda of confusing for me) That above code should spit out 6 ? Right now it's spitting out 3 only
  25. $winning_numbers = explode("|", "8|18|3,8|18|3"); while($ticket = $DB->fetch_row($query)) { $correct_numbers = 0; $correct = 0; $numbers_chosen = @explode("|","8|18|3,8|18|3"); $your_numbers = array(); $array1 = array_count_values($numbers_chosen); $array2 = array_count_values($winning_numbers); foreach($array1 as $number1 => $count1) { foreach($array2 as $number2 => $count2) { if($number2 == $number1 and $count2==$count1) $correct_numbers += $count2; } } $use = 0; echo $correct_numbers; echo "<br>"; As you can see, my $correct_numbers variable will spit out "3" because it matches 3 each INDIVIDUAL numbers from $numbers_chosen in the arrays. Now my problem is. This code wasn't supposed to take in a "," to. So essentially This should display "6" because I want it to read through each , as a new Array/Group if you will. So let's say if I changed it to: $winning_numbers = explode("|", "2|18|3,8|18|2"); $numbers_chosen = @explode("|","8|18|3,8|18|3"); It would echo out "4" As it only matches 4 of them. Once I know how to do this, I will have a full functioning lottery System on my site, I am very anxious for replies, Hope you can Help. Thank you. TLDR??: I want $correct_numbers to beable to count arrays with the comma's to
×
×
  • 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.