I have a program that simulates the Powerball Lottery game, i have been working on it for weeks now. My issue is with the quick pick option. when the quick pick numbers match the winning numbers it doesn't show the matches. If the user enters the numbers manually it does. Can anyone look at my code and tell me what adjustments to make to correct this. I'm not getting any errors it just doesnt show the matches and amount that was won.

<?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(' &nbsp; ',$aryPickedBalls),' &nbsp; PB: ',$intPowerBall,"<br>\n<br>\n";		
			echo "You picked: <br>",implode(' &nbsp; ',$aryPickedBalls2),' &nbsp; PB: ',$intPowerBall2,"<br>\n<br>\n";
			
			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 {
                  
 
                // 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(' &nbsp; ',$aryPickedBalls),' &nbsp; 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";
                 }
          
     ?>
Member Avatar for diafol

Huge amount of duplication here

<?php
	//CONFIG VARIABLES
	$no_balls = 5;
	$first_ball = 1;
	$last_ball = 59;
	
	$first_powerball = 1;
	$last_powerball = 49;

	$diff_powerball = true;

	//GET THE RANDOM NUMBERS AND POWERBALL
	function getNumbers($no_balls,$first_ball,$last_ball,$first_powerball,$last_powerball,$diff_powerball){
		$powerball = mt_rand($first_powerball,$last_powerball);
		$all_balls = range($first_ball,$last_ball);
		if(!$diff_powerball){
			$all_balls_remove_key = array_search($powerball, $all_balls);
			unset($all_balls[$all_balls_remove_key]);
		}
		shuffle($all_balls);
		$picked_balls = array_slice($all_balls,0,$no_balls); 
		$pciked_balls = sort($picked_balls);
		return array('picked'=>$picked_balls,'powerball'=>$powerball);		
	}
	//SET bad flag
	$bad = false;
	//GET LOTTERY RESULTS
	$lotteryBalls = getNumbers($no_balls,$first_ball,$last_ball,$first_powerball,$last_powerball,$diff_powerball);
	//GET MY BALLS - AUTO OR MANUAL
	if(!isset($_POST['quickP'])){
		$myBalls = getNumbers($no_balls,$first_ball,$last_ball,$first_powerball,$last_powerball,$diff_powerball);	
	}else{
		if(isset($_POST['Power']) && intval($_POST['Power']) >= $first_powerball && intval($_POST['Power']) <= $last_powerball){
			$myBalls['powerball'] = intval($_POST['Power']);
		}else{
			$bad = true;
		}
		for($x=1;$x=$no_balls;$x++){
			if(isset($_POST['num'.$x]) && intval($_POST['num'.$x]) >= $first_ball && intval($_POST['num'.$x]) <= $last_ball){
				$myBalls['picked'][] = intval($_POST['num'.$x]);
			}else{
				$bad = true;
			}
		}	
	}
	
	if(!$bad){
		//GET NUMBER OF MATCHES FOR NORMAL NUMBERS
		$no_matches = count(array_intersect($myBalls['picked'],$lotteryBalls['picked']));
		//SEE IF POWERBALLS MATCH
		$power_match = ($myBalls['powerball'] == $lotteryBalls['powerball']);
		//BUILD TABLE FOR RESULT OUTPUT
		$lotto_table_balls = "";
		$my_table_balls = "";
		$table = '<table><thead><tr><th>&nbsp;</th>';
		for($x=0;$x<$no_balls;$x++){
			$table .= '<th>Ball' . ($x + 1) .'</th>';
			$class = (in_array($myBalls['picked'][$x],$lotteryBalls['picked'])) ? ' class="match"' : '';	
			$lotto_table_balls .= "<td>{$lotteryBalls['picked'][$x]}</td>";
			$my_table_balls .= "<td{$class}>{$myBalls['picked'][$x]}</td>";
		}
		$class = ($myBalls['powerball'] == $lotteryBalls['powerball']) ? ' class="match"' : '';
		$table .= "<th>Powerball</th></tr></thead><tbody><tr><th>LOTTO</th>" . $lotto_table_balls . "<td>{$lotteryBalls['powerball']}</td></tr><tr><th>MY NUMBERS</th>" . $my_table_balls .  "<td{$class}>{$myBalls['powerball']}</td></tr></tbody></table>";
	}else{
		$table = "You didn't enter the correct numbers.";	
	}
?>

<style>.match{background-color: red;}</style>

<?php echo $table;?>

Sorry, I was bored tnight. No winnings though.

Yea i noticed that i took some of out didn't notice it when i was copying and pasting the random number function
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(' &nbsp; ',$aryPickedBalls),' &nbsp; PB: ',$intPowerBall,"<br>\n<br>\n";		
			echo "You picked: <br>",implode(' &nbsp; ',$aryPickedBalls2),' &nbsp; PB: ',$intPowerBall2,"<br>\n<br>\n";
			
			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 {
                  
 
                // 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";
				 }
			
	}
        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(' &nbsp; ',$aryPickedBalls),' &nbsp; 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";
                 }
          
     ?>

So wut do you thimk is the reason for my Quick picks not showing the matched numbers?

ok just noticed that you posted a different code. I'll let you know up front i'm new to php and don't quite understand everything that you've done. I guess my first question would be is what would the front page look like for this because when i copied your code to see how it works, it gives me a blank page. i can see how you set it up but if i could see it working it may help even more

Member Avatar for diafol

Sorry, change:

if(!isset($_POST['quickP'])){

to

if(isset($_POST['quickP'])){

I just disabled it because I don't have a form to post - just a prototype.

Sorry, that doesn't work. The page is unable to be displayed when i made that correction.

Ok i get what you are saying, so i'll have to figure out how to create an input form for it. i wanted to use lists boxes that way the user doesnt pick anything other than the numbers allowed. ok gotta do some research again to create it, i'll get back to you with what i come up with

Member Avatar for diafol

ok here's a screenshot. rough and ready, but look I matched 3 balls!

Ok but how did you select your numbers? i have that screen already. or did you just use the quick pick option? i need to have 6 selection lists for the user to pick their numbers as well. I don't understand how this has anything to do with my code.

Member Avatar for diafol

I used the quick pick option.

I don't understand how this has anything to do with my code.

You had duplication all the way through it. If you don't like what I did with it, no worries.

OK so your form will look something like this?

<form ...>
  <input type="checkbox" checked="checked" name="quickP" id="quickP" />
  <label for="quickP">Quick Pick</label>
  
  <label for="num1">Ball 1</label>
  <select name="num1" id="num1">
      <option value="1">1</option>
      ... up to 59...
  </select>
  ...four more like this...
  <label for="Power">PowerBall</label>
  <select name="Power" id="Power">
      <option value="1">1</option>
      ... up to 49...
  </select>
 <input type="submit" name="submit" ... value = "Go!" />
</form>

Thinking about it you may be better having a javascript randomizer for the form so that random numbers appear in the dropdowns. THen you can further simplify the handling code by taking out the quickP option.

Member Avatar for diafol

OK my last post on this - ignore if you don't like it. no prob.

header('Content-Type: text/html; charset=utf-8'); 
	//CONFIG VARIABLES
	$no_balls = 5;
	$first_ball = 1;
	$last_ball = 59;
	
	$first_powerball = 1;
	$last_powerball = 49;

	$diff_powerball = true;
	//winnings - incpower = include powerball match
	$winnings = array(
		1=>array('normal'=>3,'incpower'=>10),
		2=>array('normal'=>15,'incpower'=>100),
		3=>array('normal'=>100,'incpower'=>1000),
		4=>array('normal'=>300,'incpower'=>10000),
		5=>array('normal'=>500,'incpower'=>100000),
		6=>array('incpower'=>1000000)
	);

	$currency = "£";

	//GET THE RANDOM NUMBERS AND POWERBALL
	function getNumbers($no_balls,$first_ball,$last_ball,$first_powerball,$last_powerball,$diff_powerball){
		$powerball = mt_rand($first_powerball,$last_powerball);
		$all_balls = range($first_ball,$last_ball);
		if(!$diff_powerball){
			$all_balls_remove_key = array_search($powerball, $all_balls);
			unset($all_balls[$all_balls_remove_key]);
		}
		shuffle($all_balls);
		$picked_balls = array_slice($all_balls,0,$no_balls); 
		$pciked_balls = sort($picked_balls);
		return array('picked'=>$picked_balls,'powerball'=>$powerball);		
	}
	//SET bad flag
	$bad = false;
	//GET LOTTERY RESULTS
	$lotteryBalls = getNumbers($no_balls,$first_ball,$last_ball,$first_powerball,$last_powerball,$diff_powerball);
	//GET MY BALLS - AUTO OR MANUAL
	if(isset($_POST['quickP'])){
		$myBalls = getNumbers($no_balls,$first_ball,$last_ball,$first_powerball,$last_powerball,$diff_powerball);	
	}elseif(isset($_POST['manual'])){
		if(isset($_POST['Power']) && intval($_POST['Power']) >= $first_powerball && intval($_POST['Power']) <= $last_powerball){
			$myBalls['powerball'] = intval($_POST['Power']);
		}else{
			$bad = true;
		}
		for($x=1;$x<$no_balls+1;$x++){
			if(isset($_POST['num'.$x]) && intval($_POST['num'.$x]) >= $first_ball && intval($_POST['num'.$x]) <= $last_ball){
				$myBalls['picked'][] = intval($_POST['num'.$x]);
			}else{
				$bad = true;
			}
		}	
	}
	
	if(!$bad && (isset($_POST['quickP']) || isset($_POST['manual']))){
		//GET NUMBER OF MATCHES FOR NORMAL NUMBERS
		$no_matches = count(array_intersect($myBalls['picked'],$lotteryBalls['picked']));
		//SEE IF POWERBALLS MATCH
		$power_match = ($myBalls['powerball'] == $lotteryBalls['powerball']);
		//BUILD TABLE FOR RESULT OUTPUT
		$lotto_table_balls = "";
		$my_table_balls = "";
		$table = '<table><thead><tr><th>&nbsp;</th>';
		for($x=0;$x<$no_balls;$x++){
			$table .= '<th>Ball' . ($x + 1) .'</th>';
			$class = (in_array($myBalls['picked'][$x],$lotteryBalls['picked'])) ? ' class="match"' : '';	
			$lotto_table_balls .= "<td>{$lotteryBalls['picked'][$x]}</td>";
			$my_table_balls .= "<td{$class}>{$myBalls['picked'][$x]}</td>";
		}
		$class = ($myBalls['powerball'] == $lotteryBalls['powerball']) ? ' class="match"' : '';
		$table .= "<th>Powerball</th></tr></thead><tbody><tr><th>LOTTO</th>" . $lotto_table_balls . "<td>{$lotteryBalls['powerball']}</td></tr><tr><th>MY NUMBERS</th>" . $my_table_balls .  "<td{$class}>{$myBalls['powerball']}</td></tr></tbody></table>";
		
		$total_matches = $no_matches + $power_match;
		if($total_matches > 0){
			$win = ($power_match) ? $winnings[$total_matches]['incpower'] : $winnings[$total_matches]['normal'];
			$comment = "You won $currency$win! You matched a total of $total_matches ball";
			$comment .= ($total_matches > 1) ? "s" : '';
			$comment .= ($power_match) ? ", including the powerball." : ".";
		}else{
			$comment = "Sorry you didn't win this time.";	
		}
		
		
	}elseif($bad && isset($_POST['manual'])){
		$table = "You didn't enter the correct numbers.";	
	}
?>

<style>.match{background-color: red;}</style>

<?php if(isset($table))echo $table . "<p>$comment</p>";?>

<form method="post">
<?php
$p="";
for($x=0;$x<$no_balls;$x++){
	$p .= "<label for=\"num" . ($x + 1).  "\">Ball " . ($x + 1).  "</label><select name=\"num" . ($x + 1).  "\">"; 
	for($y=$first_ball-1;$y<$last_ball;$y++){
		$p .= "<option value=\"" . ($y + 1). "\">" . ($y + 1) .  "</option>";	
	}
	$p .="</select>";	
}
$p .= "<label for=\"Power\">Power</label><select name=\"Power\">";
for($y=$first_powerball-1;$y<$last_powerball;$y++){
		$p .= "<option value=\"" . ($y + 1). "\">" . ($y + 1) .  "</option>";	
	}
$p .="</select>";
echo $p;
?>


<button type="submit" name="quickP">Quick Picks</button>
<button type="submit" name="manual">Send Manual</button>

</form>

Ok kool the last code is closer to what i was looking for, thanks for stayin with me on this, i really appreciate it. I didnt mean any offense to your previous codes. but i do have one question: In order to ensure that the first 5 numbers dont have any duplicates would i just add an adjustment to line 91

The reason i asked is because when i entered "1" into each box it says that i've won $500, when there was only one match to the winning numbers

Member Avatar for diafol

OK, yes you need a way to stop duplicate values from being chosen in the form. You should do this with client side validation (js) but also check input with server-side code. I didn't include that bit.

It could be done something like this:

if(count(array_unique($myBalls['picked'])) != count($myBalls['picked'])){
	echo "BOO You chose the Same Numbers!";	
}

Ok kool, im glad you gave me another choice because i haven't worked with Java Script at all, Oh yea i also noticed that the amount won wasn't right for the number of matches. ie. if you get one number matched, it's not $3 it's 0, if you just match the powerball you win $3, but i can pretty much do that myself by referencing the the lottery website, just letting you know in case you wanted to use the program yourself in the future.

Member Avatar for diafol

OK, glad you see it. Mind you, my code isn't the best - it's just a knock-up. I'm sure it could be optimized, improved and messed with until it's reasonably good.

I included it just to illustrate the use of functions to avoid duplicating code. Also I introduced the array_slice() and the array_intersect() to get 5 numbers from a big array and to get total number of matches, respectively.

For js validation, you may like to look at jquery - there should be a number of scripts floating out there. You may find that using textboxes would be easier?

REM - when you think the thread is solved, mark it so with the link below.

Ok kool thanks again Ardav, you really helped alot, i was totally lost and as I can see i was headed in the wrong direction. I actually thought about doing textboxes but figured the selection lists would be easier for the user.

Member Avatar for diafol

OK found a js (jquery) script modified from:

http://stackoverflow.com/questions/7056018/how-to-avoid-duplicate-field-values-using-jquery

<script>
$(document).ready(function() {
  var selects = $('.normalballs');
  $('.normalballs').change(function(){
     var value = $(this).val();
     var count = 0;
     for(var i=0; i<selects.length; i++){
        if($(this).attr('id') != $(selects[i]).attr('id')) {
           var checkVal = $(selects[i]).val();
           if(value == checkVal) {
              alert("Number already selected, please select a different number");
              $("#"+$(this).attr('id')+" option[value='']").attr("selected", "selected");
           }
        }
     }
  })
});
</script>

That *should* work with:

<form method="post">
<?php
$p="";
for($x=0;$x<$no_balls;$x++){
	$p .= "<label for=\"num" . ($x + 1).  "\">Ball " . ($x + 1).  "</label><select name=\"num" . ($x + 1).  "\" class=\"normalballs\"><option value=\"\" selected=\"selected\">--- SELECT ---</option>"; 
	for($y=$first_ball-1;$y<$last_ball;$y++){
		$p .= "<option value=\"" . ($y + 1). "\">" . ($y + 1) .  "</option>";	
	}
	$p .="</select>";	
}
$p .= "<label for=\"Power\">Power</label><select name=\"Power\"><option value=\"\" selected=\"selected\">--- SELECT ---</option>";
for($y=$first_powerball-1;$y<$last_powerball;$y++){
		$p .= "<option value=\"" . ($y + 1). "\">" . ($y + 1) .  "</option>";	
	}
$p .="</select>";
echo $p;
?>
 
 
<button type="submit" name="quickP">Quick Picks</button>
<button type="submit" name="manual">Send Manual</button>
 
</form>

remember to include the reference to the jquery library in the head section before this js script:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>

OK, over and out.

Had a quick question to add to this subject. If i wanted to add another set of drop down lists to test that my winning combinations are outputting the correct results, how would i go about it? I know i would have to delete the code that randomly picks the winning numbers and replace it with code to manually pick the test numbers, but after that it is a blur, could use some help on this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.