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