master82 Posted February 8, 2007 Share Posted February 8, 2007 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 More sharing options...
offsprg01 Posted February 8, 2007 Share Posted February 8, 2007 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 More sharing options...
ToonMariner Posted February 8, 2007 Share Posted February 8, 2007 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 More sharing options...
offsprg01 Posted February 8, 2007 Share Posted February 8, 2007 or you could try the better leaner faster way of doing it. lol Link to comment https://forums.phpfreaks.com/topic/37624-number-counting/#findComment-179972 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.