Jump to content

QUick Pick Lottery Option


jetlife76

Recommended Posts

You do realize that the person you responded to in your last several esponses is a different person, right? Personally, I agree with xyph that you are half assing it and it is a bit rude to ask for advice and then to dismiss the advice you are given. I never said you had to rewrite all your code from scratch. You already have much of the "micro" logic needed - the problem is the "macro" logic - in other words the overall flow. All you need is a simple flowchart of how the logic should be. You can then re-use most of the code you already have.

 

. . . or you could just continue to tinker with it.

Link to comment
Share on other sites

Yes i did know that i was replying to different people, This is my first time with php and i am getting help from other people physically as well as on here,  that is why i didnt want to rearange my code that much. All of this could have been avoided honestly, because i was only asking if there were a way to edit the code to add that particular option. I understand that you were saying all i had to do was rework my logic, but when i said i didnt have tthe time to redo everything that i've just learned how to do, you all took it as a disrespect and me half assing it. like i stated earlier i am new to php and the syntax is what gives me the most problem, i understand how the logic must work but wording doesn't come to me as easy as it does to others.

Once again thank you guys for your help i am referencing the advise i was given on here, will let you know what i come up with.

Link to comment
Share on other sites

All of this could have been avoided honestly, because i was only asking if there were a way to edit the code to add that particular option. I understand that you were saying all i had to do was rework my logic, . . .

Yeah, there probably is a way to "simply" add the functionality you were asking for. The problem is that your current logic is terrible and I (nor probably anyone else) can figure out what to put where. If your logic is so complex that YOU don't understand where to implement a simple if() statement, then the logic is flawed and/or overcomplicated. Again, you don't need to rewrite everything from scratch. Just identify the blocks of code that perform specific functions and put them in a logical order. I already gave you an example to follow.

Link to comment
Share on other sites

  • 2 weeks later...

OK i figured out how to get it to work, but for some reason it is not checking to see if the quick picks match the winning numbers. i thought the foreach statement i put in would handle it, but evidently my wording is wrong, If anyone has an idea of waht i should do, their input would be appreciated.

Here's my new code:


<?php

        $intGrandPize = 10000000;
         $intRegCount = 5;
         $intMaxReg = 59;
         $intMaxPB = 49;
	 $aryPick = array();
         $intPower = 0;
	 $intPowerBall = rand(1,$intMaxPB);

 if (isset($_POST['quickP'])){
	  //$intPowerBall = rand(1,$intMaxPB);
	  $aryAllBalls = range(1,$intMaxReg); // array of numbers 1 - 59
                 shuffle($aryAllBalls); // Randomize their order
                 $aryAllBalls = array_chunk($aryAllBalls,$intRegCount); // The above breaks up into an array with 5 numbers each
                 // [0] contains the first 5 balls of all balls randomized, these are what are "picked"
                 $aryPickedBalls = $aryAllBalls[0]; 
                sort($aryPickedBalls); // Sort them for display

	  $intPowerBall2 = rand(1,$intMaxPB);
	  $aryAllBalls2 = range(1,$intMaxReg); // array of numbers 1 - 59
                 shuffle($aryAllBalls2); // Randomize their order
                 $aryAllBalls2 = array_chunk($aryAllBalls2,$intRegCount); // The above breaks up into an array with 5 numbers each
                 // [0] contains the first 5 balls of all balls randomized, these are what are "picked"
                 $aryPickedBalls2 = $aryAllBalls2[0]; 
                sort($aryPickedBalls2); // Sort them for display
		echo "YOUR WINNING NUMBERS ARE: <br>",implode('   ',$aryPickedBalls),'   PB: ',$intPowerBall,"<br>\n<br>\n";		
		echo "You picked: <br>",implode('   ',$aryPickedBalls2),'   PB: ',$intPowerBall2,"<br>\n<br>\n";

		foreach($aryPick as $key=>$val) {
                     if (in_array($val,$aryPickedBalls2)) {
                         echo '<strong>',$val,'</strong> ';
                     }
                     else {
                         echo $val,' ';
                         unset($aryPick[$key]); // Remove it since it didn't match
                     }
                 }
                 $bMatchPB = ($intPower == $intPowerBall2); // Set here since checked in 3 places...
                 if ($bMatchPB) {
                     echo 'PB: <strong>',$intPower,"</strong><br>\n<br>\n";
                 }
                  else {
                  

                // At this point, $aryPick will only contain matching numbers...
                 $intMatches = count($aryPick);
                 echo 'You matched '.$intMatches,' numbers and did ';
                 if (!$bMatchPB) { echo 'not '; }
                 echo "match the PowerBall number.<br><br>\n\n";
			 }
		if ($intMatches>=3 || $bMatchPB) {
                     $intWinnings = 0;
                     switch ($intMatches) {
                         case 0:
                                 if ($bMatchPB) { $intWinnings = 3; }
                                 break;
                         case 1:
                                 if ($bMatchPB) { $intWinnings = 4; }
                                 break;
                         case 2:
                                 if ($bMatchPB) { $intWinnings = 7; }
                                 break;
                         case 3:
                                 if ($bMatchPB) {
                                     $intWinnings = 100;
                                 } else {
                                     $intWinnings = 7;
                                 }
                                 break;
                         case 4:
                                 if ($bMatchPB) {
                                     $intWinnings = 10000;
                                 } else {
                                     $intWinnings = 100;
                                 }
                                 break;
                         case 5:
                                 if ($bMatchPB) {
                                 $intWinnings = $intGrandPize;
                                 } else {
                                     $intWinnings = 200000;
                                 }
                                 break;
                         default:
                                 echo "ERROR: Winning Combination not defined in systen!!!<br>\n";
                     }
                     echo "<strong>YOU ARE A WINNER!!!!</strong><br>\n";
                     echo 'You Won: $'.number_format($intWinnings,0),"<br>\n";
                 }	 
}
        elseif (count($_POST)>0)  {
             $aryPick = array();
             $intPower = 0;
             for($t=1;$t<=$intRegCount;$t++) {
                 if (isset($_POST['num'.$t])) {
                     $intPick = (int)$_POST['num'.$t];
                     if ($intPick > 0 && $intPick <= $intMaxReg && !in_array($intPick,$aryPick)) {
                         $aryPick[] = $intPick;
                     }
                 }
             }
             if (isset($_POST['Power']) && (int)$_POST['Power'] > 0 && $_POST['Power'] <= $intMaxPB) {
                 $intPower = (int)$_POST['Power'];
             }
             if (count($aryPick) < 5 || $intPower == 0) {
                 echo "<font color='red'>'*Five unique numbers and a PowerBall selection are Required*'</font>";;
             }
             else {
                 // Have valid numbers...

                sort($aryPick); // For if you are going to display them, they will be in order...

                // Pick your winners

                $aryAllBalls = range(1,$intMaxReg); // array of numbers 1 - 59
                 shuffle($aryAllBalls); // Randomize their order
                 $aryAllBalls = array_chunk($aryAllBalls,$intRegCount); 
                // The above breaks up into an array with 5 numbers each
                 // [0] contains the first 5 balls of all balls randomized, these are what are "picked"
                 $aryPickedBalls = $aryAllBalls[0]; 
                sort($aryPickedBalls); // Sort them for display

                

                echo "YOUR WINNING NUMBERS ARE: <br>",implode('   ',$aryPickedBalls),'   PB: ',$intPowerBall,"<br>\n<br>\n";

                echo "You Picked: ";
                 foreach($aryPick as $key=>$val) {
                     if (in_array($val,$aryPickedBalls)) {
                         echo '<strong>',$val,'</strong> ';
                     }
                     else {
                         echo $val,' ';
                         unset($aryPick[$key]); // Remove it since it didn't match
                     }
                 }
                 $bMatchPB = ($intPower == $intPowerBall); // Set here since checked in 3 places...
                 if ($bMatchPB) {
                     echo 'PB: <strong>',$intPower,"</strong><br>\n<br>\n";
                 }
                 else {
                     echo 'PB: '.$intPower,"<br>\n<br>\n";
                 }

                // At this point, $aryPick will only contain matching numbers...
                 $intMatches = count($aryPick);
                 echo 'You matched '.$intMatches,' numbers and did ';
                 if (!$bMatchPB) { echo 'not '; }
                 echo "match the PowerBall number.<br><br>\n\n";}}

                // HERE YOU WOULD DO SOMETHING TO SAY HOW MUCH THEY WON

			$intMatches = count($aryPick);
			$bMatchPB = ($intPower == $intPowerBall);
                 if ($intMatches>=3 || $bMatchPB) {
                     $intWinnings = 0;
                     switch ($intMatches) {
                         case 0:
                                 if ($bMatchPB) { $intWinnings = 3; }
                                 break;
                         case 1:
                                 if ($bMatchPB) { $intWinnings = 4; }
                                 break;
                         case 2:
                                 if ($bMatchPB) { $intWinnings = 7; }
                                 break;
                         case 3:
                                 if ($bMatchPB) {
                                     $intWinnings = 100;
                                 } else {
                                     $intWinnings = 7;
                                 }
                                 break;
                         case 4:
                                 if ($bMatchPB) {
                                     $intWinnings = 10000;
                                 } else {
                                     $intWinnings = 100;
                                 }
                                 break;
                         case 5:
                                 if ($bMatchPB) {
                                 $intWinnings = $intGrandPize;
                                 } else {
                                     $intWinnings = 200000;
                                 }
                                 break;
                         default:
                                 echo "ERROR: Winning Combination not defined in systen!!!<br>\n";
                     }
                     echo "<strong>YOU ARE A WINNER!!!!</strong><br>\n";
                     echo 'You Won: $'.number_format($intWinnings,0),"<br>\n";
                 }
          
     ?>

Link to comment
Share on other sites

Volunteer staff and members are helping you out of their own precious free time, no one here HAS to help you. A little respect goes a long way.

 

As far as your code is concerned. In my opinion it would be quicker to recode it differently then to 'tinker' with it. Sometimes you just need to take in the advice, scrap what you have and start over. That way you will avoid hours of some what wasted time and bad headaches.

Link to comment
Share on other sites

Ok i tried to recode it as you can see, the only issue i have is getting the matched numbers to display for the quick picks. Since everyone hates my code so much, i think some suggestions should be given when you suggest that i recode it. I took the advice from earlier posts and recoded it as close as i could to what was suggested. As i've stated before i am new to php , what seems so very simple to you guys is like chineses to me at times. At least tell me what im doing wrong instead of just saying i should do it over. Once again thanks for your input! :D

Link to comment
Share on other sites

At least tell me what im doing wrong instead of just saying i should do it over. Once again thanks for your input! :D

 

I did tell you what was wrong with your code. It had no discernible logic - which was why no one could simply state "insert some code here". You had no idea what to do where because the logic was terrible.

 

I think you really need to pull out a sheet of paper and figure out your logic, then go back and code it. The flow of your code seems pretty haphazard.

I even provided a sample high-level logic that would at least provide a jumping off point. As I stated previously, no one was stating you should just throw out all your current code. Most of it could be reused - you just needed to put it in a more logical order. Aside from rewriting it for you I don't know what you expect.

Link to comment
Share on other sites

Ok i thought that's what i had done, i used the example of how it should flow, if you look at my new code it's pretty much set up like your example. But nevermind i will just redo it all over again, And when i stated that no suggestions were made, i was meaning any suggestions as to where you would put what or what order certain attributes of my code should go before the other.  I thought if i set up the quick pick, then the manual post, then decide how much was won was a pretty good logic. You could've said, "Well maybe if you put this here because it does such & such, and you don't need to repeat this here..., that's the kind of suggestions i thought i would be able to get. Everyone telling me my logic is flawed and not telling me what's flawed about it, doesn't help. I'm not on here for anyone to do it for me, i really want to learn PHP, but it seems as if everyone is coming at me as if i should know it like the back of my hand. It's pretty clear that this post went from helping me to judging me, a long time ago. It's cool though, i will take whatever was suggested to me and just "scrap it" and start over. No disrespect was ever intended from me in this post i came here to see if i could get help, instead i got badgered and shunned. You guys have a great day and continue to help others, i'm done with this!!!

 

Link to comment
Share on other sites

You could've said, "Well maybe if you put this here because it does such & such, and you don't need to repeat this here..., that's the kind of suggestions i thought i would be able to get. Everyone telling me my logic is flawed and not telling me what's flawed about it, doesn't help.

 

As I just stated we couldn't give you that kind of advice because we couldn't understand the logic. I only had a very vague idea of what you were trying to accomplish and I'm not going to take hours of my time reading your code line by line trying to interpret what you really meant to accomplish in order to try and provide that type of help. If you would have provided clear comments in your code to explain the logic that would have helped too.

 

No one could tell you anything specific about what was wrong because it was just too haphazard. If you have a bad foundation where you want to build a home do you go ahead and build anyway or do you put in a new foundation? The same applies for programming. If you have bad logic to begin with and then try to fix something by "tinkering" with it you are way beyond anyone to help you with the code you have.

 

You were given advice, which was to simply pull out a sheet of paper and map out some appropriate logic. I never said all of your code was crap and you needed to start everything over. Only that you needed a more logical approach. Your response was that you were just going to tinker with it.

 

Ok i thought that's what i had done, i used the example of how it should flow, if you look at my new code it's pretty much set up like your example.

No, it isn't. The very high level flow I provided showed that you should determine the user's numbers (either user defined or quick pick - THEN you should perform the logic to determine the results of the user's picks. The code you last posted duplicated the logic for determining whether the user won or not. Go back and look at the high-level logic I provided previously.

 

Again, you have some good code in there. You just need to take a step back, determine the correct flow for the logic and then reuse the code you have or implement new code where necessary.

Link to comment
Share on other sites

Ok so how is it that i can pretty much determine what's doing what on the form, but no one else can? Like you stated in your first post, "I'm not even gonna look at your code" tell me how can you begin to help someone if you don't even care to look at what they are doing? But i'm the one being disrespectful? then you go back and take a glimpse at it and determine that my logic is flawed? if it was flawed i don't think the program would work at all. secondly i have finished this program by adding a simple "if" statement, which someone else helped me with. So what does that say about the advice i was given on here? The person that helped me with this simply showed me how to implement the if statement so that it would do the same functions that the form had before i added the quick Pick. So you can say i "Half Assed It" but honestly i will say that someone else was half assing it, but i won't call any names, lol. I think it was very unprofessional of whomever (No Names) decided to turn this post into a personal problem rather than a helpful solution. This all could've been avoided had you or the other person/ persons simply skipped my post if you didnt want to help me. As one of you stated, "there is always a way to fix it", but you all wanted me to do it the way you wanted it done. there are many ways to do this project and yours just didnt fit with mine, thanks for the help and headaches, you guys are the best!!! LMAO!!!!! ::)

Link to comment
Share on other sites

You know, I was trying to be helpful and reach out with an olive branch after all the negativity in this thread and you just come right back with an attitude.

 

The reason I didn't look through your code initially is that you simply posted too much without giving any context, no helpful comments, etc. As, I stated you shouldn't have to guess where the problem is if your code was written in a logical formal. Having poor logic doesn't necessarily mean something wont work. It could mean that the approach is so overcomplicated and superfluous that trying to fix a bug or add a feature is more complicated than it needs to be (such as this was).

 

I'll admit some were a little overbearing in their response, but you have to take some responsibility for your own responses. Also, as I pointed out in the last code you posted you are completely duplicating the logic to determine whether the user won anything based upon whether they submitted their own numbers or a quick pick. That is the type of flawed logic I was referring to. Whether the user submitted their numbers or used a quick pick has no bearing on what and how they win. By duplicating the logic you are making it more complicated than it needs to be. You should determine the user's numbers (quick pick or submitted) - then determine their winnings.

Link to comment
Share on other sites

well actually i wasnt referring to you individually, because you were the only one that was actually offering a solution, diddn't mean for you to take offense, the duplication in the last code was a paste error, i actually had the code as you suggested. I noticed it when you mentioned it was a duplication in previous posts. I want to thank you for your help personally, but the others seem to only want to take shots at me and naturally i wen t o n the defensive. But as i can tell, someone has sort of black listed me on this site because my other posts haven't even been looked at. but it's cool, there are plenty of other sites like this one. Once again thanks for your offerings in helping me!!!!

Link to comment
Share on other sites

But as i can tell, someone has sort of black listed me on this site because my other posts haven't even been looked at. but it's cool, there are plenty of other sites like this one.

 

No one has black listed you. I just looked at your other posts and they are, in my opinion, too general and vague which is probably why no one has responded. For example your post "Random Numbers" has been read over 100 times. In the post you ask for someone to explain how a quick pick option could be implemented and then post all your code. It is unclear from that post if you are asking about how to implement the option for a user to select a quick pick, how to actually implement logic to generate the quick pick, or what.

 

When a question is vague like that and the user is unable or unwilling to specify the specific code section that applies to their question, many users are hesitant to respond. The posts can go on for pages because the helper is constantly having to ask the OP for clarification. And, in many cases, the OP is unable to implement anything without serious hand holding. In other words they become a lot of work. We all do this for free because we enjoy helping people. But, when some users sense that trying to respond to a certain post will become tedious and unfulfilling they simply choose not to respond.

Link to comment
Share on other sites

Here we go again, instead of Posting something relevant to the issue, he(XYPH) just adds to the negative. I never asked anyone to do this for me, i simply asked for assistance on how it could be done, MJDAMATO and MasterAce are the only ones that are actually offering help. You (XYPH) need to work on your people skills because in the real world if you talk down to a customer like this it won't be as simple as them just leaving, you'll suffer physical harm. I don't see anywhere in this thread where you offered any help, so why are you posting anything, why are you even looking at this post.

So if you are not here to add something to the solution, then you my friend are the problem. If you look back you started all the negative, i don't care who you are on this site or in real life, You will not speak/type to me any kind of way other than with the respect that i give.  Anyway Thanks once again MJDAMATO and Master Ace for your help. I am actually working on recoding this in a better logical way eventhough i have found a way to make my existing code work. Once i have finished it, if you would like to see it i can either post it or email it to you. because i feel like i owe it to you for sticking with me and i don't want "You" to feel like you wasted your time. I do want to learn this language, i just had a time constraint for this project and had to find an easier solution because i had already put so much into it before coming on here. @ XYPH :wtf:

Link to comment
Share on other sites

  • 2 weeks later...

I do have one last question on this topic if anyone is still looking at it. i wanted to check to make sure that when i have winning combinations that the results are output correctly. For example:

Creating another set of List Boxes to test the winning combinations.

Say i selected 1,2,3,4,5 and PB:6 as the test (Winning Numbers)

the user picks are 1,2,3, 4,7 PB:6

The results would be: Matched 4 numbers and the powerball - You're a winner you won (x) amount

This doesn't have to be for the quick pick as i believe it would be nearly impossible to do.

Anyone have a clue as to how i would approach this?

Link to comment
Share on other sites

I would create a variable to indicate whether you are in 'test' mode or not. Since you appear to have multiple pages for this logic I'd probably save this as a session or cookie value. So, on the page where you would want to start the testing process (the form for the user to enter thier picks) do something like this:

session_start();
$_SESSION['test'] = 1; //Set to 0 when NOT in test mode

 

On your form script check to see if you are in test mode or not. If yes, then include addition fields in the form to enter the 'winning' numbers.

 

On the processing script check to see if you are in test mode or not. If yes, then bypass the code to dynamically determine the winning numbers and instead use the numbers sent in the post data

Link to comment
Share on other sites

sorry but i'm not quite following you on the test/session part.  Will this give me the results for all numbers matched, or will i be able to try a variety of match combos? and i have never even heard of this method that you are telling me to use so could you provide what the syntax would look like? I'm not asking you to do it exactly how it should be for this particular program, but i looked it up and can't figure out how to do it

Link to comment
Share on other sites

I'm not sure what more to explain without actually writing code for you. Simply set a flag (in the example I provided using a session variable) to determine if you want the scripts to run in "test" mode or not. There is nothing to "look up". It is up to YOU to determine what the application will do differently in test mode.

 

As per your request, the test mode needs to allow you to pick your numbers AND set the winning numbers. So, the form will need to allow for additional input fields for the winning numbers

//Normal form goes here
//For user to enter their picks

if($_SESSION['test'])
{
    //Additional form goes here for you to enter the winning numbers when in test mode
}

 

Then on the processing page, if you are in test mode you need to use the winning numbers passed from the form instead of the current logic for determining winning numbers

 

if($_SESSION['test'])
{
    //Set winning numbers based upon additional form fields
}
else
{
    //Set winning numbers based on current logic
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.