Jump to content

Number Counting


master82

Recommended Posts

I have a very simple lottery script for my game site. The only way to win anything is to match all 5 number.

I want to modify this so that people who gain some numbers also win something.

 

The table stores each number the player picks in a new field

eg:

num1= 10

num2= 12

etc...

 

I run the script and it identifies who has matched all the numbers by:

 

$winners = mysql_query("SELECT * FROM tickets WHERE num1='{$num[0]}' AND num2='{$num[1]}' AND num3='{$num[2]}' AND num4='{$num[3]}' AND num5='{$num[4]}' AND lotteryid='{$retval['lotteryid']}'", $db);

 

from that i get the user ids and reward.... simple.

 

But, does anyone know how I could go about counting the number of matches, so that I can also reward those who get 3 number for example?

 

Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/37624-number-counting/
Share on other sites

i'd try this

 

totalmatch = 0;

 

if (num1 = match) {

<tab>totalmatch = totalmatch + 1;

}

if num2 = match) {

<tab>totalmatch = totalmatch + 1;

}

if num3 = match) {

<tab>totalmatch = totalmatch + 1;

}

if num4 = match) {

<tab>totalmatch = totalmatch + 1;

}

if num5 = match) {

<tab>totalmatch = totalmatch + 1;

}

 

if (totalmatch == 3 OR totalmatch == 4) {then do something};

if (totalmatch == 5) {then do something even better};

 

 

 

hth

Link to comment
https://forums.phpfreaks.com/topic/37624-number-counting/#findComment-179956
Share on other sites

OK elegant way of doing this....

 

Place all these numbers into arrays...

 


$numbs = array (5,11,12,24,33); // numbers user picked

$result = array (6,11,24,29,33); // the numbers drawn.

$check = array_intersect($numbs, $result); // whih ones matched

$matched = count($check); // how many matched

swicth ($matched) // decide what to do based on number of matches.
{
case 5:
  echo "You matched all 5 - JACKPOT";
  break;
case 4:
  echo "You matched 4 - here's 20p";
  break;
case 3:
  echo "You matched 3 - 1p";
  break;
default:
  echo "Sorry you did not win a bean."
}

Link to comment
https://forums.phpfreaks.com/topic/37624-number-counting/#findComment-179968
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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