Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. <?php
  2. //updateSummary.php
  3. //Updates Summary table for json square counts of open/biddable games
  4. //This script should be triggered upon a new bid being purcahsed whether for free to cost based bids.
  5.  
  6. //Author: Brett Kokinadis
  7. //Dec 6, 2017. - v.1
  8.  
  9. //Global Settings
  10. include 'config/config.config';
  11.  
  12. //Checkf or game eligibility
  13.  
  14. $getGame = "SELECT GameID FROM Games WHERE BettingClosed=0 AND WinnersProcessed = 0";
  15. $game = $dbc->query($getGame);
  16.  
  17. //No Games found
  18. if ($game->num_rows == 0) {
  19. notReady();
  20. die();
  21. }
  22.  
  23.  
  24. while ($gameFetch = $game->fetch_assoc()) {
  25.  
  26. //Get the quarters for the Game that have BuyBoxEntries
  27. $gameID=$gameFetch["GameID"];
  28.  
  29. $getSquaresBetS = "SELECT QTR, Square, SUM(Qty) AS Qty FROM BoxBuys WHERE GameID=$gameID GROUP BY Qtr, Square";
  30. echo $getSquaresBetS;
  31. $getSquaresBetsQ = $dbc->query($getSquaresBetS);
  32.  
  33.  
  34. //initilize default 0's for square box and qty count array to allow for 0 int when not in reply.
  35. //Creating Variables $s1 - $s100 and setting value = 0, needed for array - > json encode so that when sql replies with only purchased squares others have default values.
  36.  
  37. $i=0;
  38.  
  39. for($i = 1; $i <= 100; $i++) {
  40. ${"s$i"} = 0;
  41. }
  42.  
  43. //Creating Variables for $q1 - $q100 and setting value = 0, needed for array - > json encode so that when sql replies with only purchased squares others have default values.
  44.  
  45. $j=0;
  46.  
  47. for($j = 1; $j <= 100; $j++) {
  48. ${"q$j"} = 0;
  49. }
  50.  
  51. $qtr=$squareFetch["QTR"];
  52.  
  53. //Overwrite default $S## value from SQL response
  54. while ($squareFetch= $getSquaresBetsQ->fetch_assoc()) {
  55.  
  56. $k = 0;
  57.  
  58. //Get Qtr, Squares, Qty for Game ID
  59.  
  60. $BoxSquare = $squareFetch["Square"];
  61. $qty = $squareFetch["Qty"];
  62.  
  63. for($k = 1; $k <= 100; $k++) {
  64. if ($BoxSquare = $k) {
  65. ${"s$k"} =$BoxSquare ;
  66. ${"q$k"} =$qty;
  67. }
  68.  
  69. }
  70.  
  71. }
  72.  
  73.  
  74. //Get Game Pool Size $
  75. $getPoolSizeS = "SELECT Sum(Cost) AS PoolSize FROM BoxBuys WHERE GameID=$gameID";
  76. $getPoolSizeQ = $dbc->query($getPoolSizeS);
  77. $poolSizeA= $getPoolSizeQ->fetch_assoc();
  78. $poolSize=$poolSizeA["PoolSize"];
  79.  
  80. Echo "Pool Size for ".$gameID." = $".$poolSize."\n";
  81.  
  82.  
  83. ///need to build json for quart and db update or insert
  84.  
  85.  
  86.  
  87.  
  88.  
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. /*
  97.  
  98. INSERT INTO <table> (field1, field2, field3, ...)
  99. VALUES ('value1', 'value2','value3', ...)
  100. ON DUPLICATE KEY UPDATE
  101. field1='value1', field2='value2', field3='value3', ...
  102. */
  103.  
  104.  
  105. //No games available, or game is not eligible for processing.
  106. function notReady()
  107. {
  108. echo "Sorry, no games eligible for summarization update.\n\n";
  109. die();
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement