Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //updateSummary.php
- //Updates Summary table for json square counts of open/biddable games
- //This script should be triggered upon a new bid being purcahsed whether for free to cost based bids.
- //Author: Brett Kokinadis
- //Dec 6, 2017. - v.1
- //Global Settings
- include 'config/config.config';
- //Checkf or game eligibility
- $getGame = "SELECT GameID FROM Games WHERE BettingClosed=0 AND WinnersProcessed = 0";
- $game = $dbc->query($getGame);
- //No Games found
- if ($game->num_rows == 0) {
- notReady();
- die();
- }
- while ($gameFetch = $game->fetch_assoc()) {
- //Get the quarters for the Game that have BuyBoxEntries
- $gameID=$gameFetch["GameID"];
- $getSquaresBetS = "SELECT QTR, Square, SUM(Qty) AS Qty FROM BoxBuys WHERE GameID=$gameID GROUP BY Qtr, Square";
- echo $getSquaresBetS;
- $getSquaresBetsQ = $dbc->query($getSquaresBetS);
- //initilize default 0's for square box and qty count array to allow for 0 int when not in reply.
- //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.
- $i=0;
- for($i = 1; $i <= 100; $i++) {
- ${"s$i"} = 0;
- }
- //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.
- $j=0;
- for($j = 1; $j <= 100; $j++) {
- ${"q$j"} = 0;
- }
- $qtr=$squareFetch["QTR"];
- //Overwrite default $S## value from SQL response
- while ($squareFetch= $getSquaresBetsQ->fetch_assoc()) {
- $k = 0;
- //Get Qtr, Squares, Qty for Game ID
- $BoxSquare = $squareFetch["Square"];
- $qty = $squareFetch["Qty"];
- for($k = 1; $k <= 100; $k++) {
- if ($BoxSquare = $k) {
- ${"s$k"} =$BoxSquare ;
- ${"q$k"} =$qty;
- }
- }
- }
- //Get Game Pool Size $
- $getPoolSizeS = "SELECT Sum(Cost) AS PoolSize FROM BoxBuys WHERE GameID=$gameID";
- $getPoolSizeQ = $dbc->query($getPoolSizeS);
- $poolSizeA= $getPoolSizeQ->fetch_assoc();
- $poolSize=$poolSizeA["PoolSize"];
- Echo "Pool Size for ".$gameID." = $".$poolSize."\n";
- ///need to build json for quart and db update or insert
- }
- /*
- INSERT INTO <table> (field1, field2, field3, ...)
- VALUES ('value1', 'value2','value3', ...)
- ON DUPLICATE KEY UPDATE
- field1='value1', field2='value2', field3='value3', ...
- */
- //No games available, or game is not eligible for processing.
- function notReady()
- {
- echo "Sorry, no games eligible for summarization update.\n\n";
- die();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement