コード例 #1
0
     $sql = "SELECT TIMESTAMPDIFF(MINUTE, '{$prev_timestamp}', '{$curr_timestamp}')";
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $record = $stmt->fetch();
     $minutes_elapsed = $record[0];
     // determine number of blocks grown
     $prevGrowth = $cityInfo->sectorBlocks[$prevSector] + $minutes_elapsed;
     // cap value if it is larger than number of blocks
     $prevGrowth = min($prevGrowth, $nBlocks - $nUsedBlocks);
     // update blocks value
     $sql = "UPDATE CityBlocks SET nBlocks={$prevGrowth} WHERE cityID={$cityID} AND sector='{$prevSector}'";
     $conn->exec($sql);
 }
 // update stuff
 $cityInfo = CityData::getCityInfo($cityName, $username);
 $nUsedBlocks = CityData::getUsedBlocksCount($cityInfo);
 // update current with growth
 if ($currentSector != SECTOR_NONE && $nBlocks > $nUsedBlocks) {
     // determine growth level
     $nBlocks = min($cityInfo->sectorBlocks[$currentSector] + $growth, $nBlocks - $nUsedBlocks);
     // update blocks value
     $sql = "UPDATE CityBlocks SET nBlocks={$nBlocks} WHERE cityID={$cityID} AND sector='{$currentSector}'";
     $conn->exec($sql);
 }
 // make current sector name into mysql form
 if ($currentSector == SECTOR_NONE) {
     $currentSector = "NULL";
 } else {
     $currentSector = "'{$currentSector}'";
 }
 // update sector