Skip to content
Advertisement

How to calculate win chance ticket in percentage

I’m trying to calculate a win chance from buying a freebies ticket in the percentage of each user that has been recorded in the database

here is my freebies table

the total number of tickets is 10

  • user id 60 have a 5 tickets
  • user id 50 have a 3 tickets
  • user 4 have 2 tickets

so I want to calculate on each user how much win chance they get

for example :

  • user 60: 70% win chance
  • user 50: 25% win chance
  • user 4: 5% win chance

how to calculate it in PHP code based on user id?

Advertisement

Answer

You can use next simple query:

test SQL query

Below is PHP implementation:

PHP test

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement