kesm0
kesm0

Reputation: 875

Bet application, get odds of a winner team

I got 2 mysql tables:

Match:
- id
- team1_id
- team2_id
- odds_team1
- odds_team2

Bet:
- id
- date
- amount
- winner_prevision (team1_id or team2_id)

I need to display bet's potential benefit, depending on the winner_prevision.

Formula : amount * (odds_team1 or odds_team2)

So i dont know how (mysql, php or both) can i get the correct odds_team after choosing the winner_prevision.

Maybe my tables composition is wrong, i'm listening on each suggestion !

Upvotes: 0

Views: 311

Answers (1)

GrahamTheDev
GrahamTheDev

Reputation: 24945

Really you should have 3 tables here

MATCH:
- match_id
- team1_id
- team2_id

ODDS

- match_id
- team_id
- odds

Bet:

- id
- match_id
- date
- amount
- winner_prevision (team1_id or team2_id)

Then your queries are easy (although this query is probably very wrong - you should use JOIN but I am trying to show the logic - if the actual query doesn't work then apologies!)

SELECT odds.odds AS odds, bet.amount AS amount, amount * odds AS `total` 
FROM odds, bet 
WHERE odds.team_id = Bet.winner_prevision 
AND MATCH.match_id = Bet.match_id

Hopefully the logic above makes sense - and the important part to note is the fact you can multiply within your mysql query amount * odds

Upvotes: 1

Related Questions