matchTable.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. include_once __DIR__ . '/webDbConnection.php';
  3. $conn = new WebDbConnection( );
  4. $countryId = $_POST['countrySelector'];
  5. $leagueId = $_POST['leagueSelector'];
  6. $conn->getBettingStats($leagueId);
  7. $matches = $conn->getMatches($countryId, $leagueId);
  8. $leagueInfo = $conn->getLeagueInfo($leagueId)[0];
  9. $betMarginHome = 1 + ($leagueInfo['betMarginHome'] / 100);
  10. $betMarginDraw = 1 + ($leagueInfo['betMarginDraw'] / 100);
  11. $betMarginAway = 1 + ($leagueInfo['betMarginAway'] / 100);
  12. ?>
  13. <head>
  14. <link rel="stylesheet" href="style.css">
  15. </head>
  16. <body>
  17. <iframe name="hiddenFrame" class="hide"></iframe>
  18. <table id="matchTable">
  19. <thead>
  20. <tr>
  21. <th hidden/>
  22. <th>Datum</th>
  23. <th>Hemma lag</th>
  24. <th>Borta lag</th>
  25. <th>Odds 1</th>
  26. <th>Odds X</th>
  27. <th>Odds 2</th>
  28. <th>1, X , 2</th>
  29. <th>Bet Odds</th>
  30. <th>Bet Amount</th>
  31. <th>&nbsp;</th>
  32. </tr>
  33. </thead>
  34. <tbody>
  35. <?php
  36. foreach ($matches as $match) {
  37. echo "<form id='makeBetFormId' action='makeBet.php' method='post' target='hiddenFrame'>";
  38. echo "<tr>";
  39. echo "<td hidden><input hidden id='gameId' name='gameIdName' value='" . $match['id'] . "'/>";
  40. echo "<td>".$match['gameDate'] . "</td>";
  41. echo "<td>".$match['homeTeamName'] . "</td>";
  42. echo "<td>".$match['awayTeamName'] . "</td>";
  43. echo "<td>". round((100 / $match['homeWinPercent']) * $betMarginHome, 2) . "</td>";
  44. echo "<td>". round((100 / $match['drawPercent']) * $betMarginDraw, 2) . "</td>";
  45. echo "<td>". round((100 / $match['awayWinPercent']) * $betMarginAway, 2) . "</td>";
  46. echo "<td><select name='betTypeName'>
  47. <option value='1'>1</option>
  48. <option value='X'>X</option>
  49. <option value='2'>2</option>
  50. </select></td>";
  51. echo "<td><input id='betOdds' name='betOddsName' type='number' step='.01'/></td>";
  52. echo "<td><input id='betAmount' name='betAmountName' type='number' step='.01'/></td>";
  53. echo "<td><input id='button' type='submit'/></td>";
  54. echo "</form>";
  55. echo "</tr>";
  56. }
  57. ?>
  58. </tbody>
  59. </table>
  60. <h2>Stats</h2>
  61. <?php
  62. $betStats = $conn->getBettingStats($leagueId)[0];
  63. $wins = 0;
  64. $losses = 0;
  65. $result = 0;
  66. $pendingResult = 0;
  67. foreach ($betStats as $betStat) {
  68. if ($betStat['homeScore'] < 0) {
  69. $pendingResult++;
  70. }
  71. if ($betStat['betOn'] === "1") {
  72. $result -= $betStat['betAmount'];
  73. if ($betStat['homeScore'] > $betStat['awayStat']) {
  74. $wins++;
  75. $result = $result * ($betStat['betAmount'] * $betStat['betOdds']);
  76. } else {
  77. $losses++;
  78. }
  79. }
  80. if ($betStat['betOn'] === "X") {
  81. $result -= $betStat['betAmount'];
  82. if ($betStat['homeScore'] == $betStat['awayStat']) {
  83. $wins++;
  84. $result = $result * ($betStat['betAmount'] * $betStat['betOdds']);
  85. } else {
  86. $losses++;
  87. }
  88. }
  89. if ($betStat['betOn'] === "2") {
  90. $result -= $betStat['betAmount'];
  91. if ($betStat['homeScore'] < $betStat['awayStat']) {
  92. $wins++;
  93. $result = $result * ($betStat['betAmount'] * $betStat['betOdds']);
  94. } else {
  95. $losses++;
  96. }
  97. }
  98. }
  99. echo "<p>Pending Result: $pendingResult</p>";
  100. echo "<p>Wins: $wins</p>";
  101. echo "<p>Losses: $losses</p>";
  102. echo "<p>Result: $result</p>";
  103. ?>
  104. </body>