?> </div> <div> <?php echo form_label('Content', 'body'); ?> <?php echo form_textarea('body', repopulate($post->body, $this->input->post('body'))); ?> </div> <div> <?php $attributes['class'] = 'inline'; ?> <?php echo form_label('Active', 'active', $attributes); ?> <?php echo form_checkbox('active', 'active', repopulate(is_active($post->active), $this->input->post('active'))); ?> </div> <p><?php echo form_submit('delete', 'Delete'); echo form_submit('update', 'Update'); ?> </p> </fieldset> </form>
function verify($s_name, $s_id2) { // Start session session_start(); // For MySQL $servername = 'localhost'; $username = '******'; $password = '******'; $dbname = 'leaguestats'; // Establish connection $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { $conn->close(); die("Connection failed: " . $conn->connect_error); } $s_id = 0; $url = 'https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/' . rawurlencode($s_name) . '?api_key=9073dedb-d0e0-43db-8557-9ae31bf7967e'; $json = file_get_contents($url); $obj = json_decode($json, true); if (empty($obj)) { $s_id = -1; } else { $temp = preg_replace('/\\s/', '', $s_name); $temp = strtolower($temp); $s_id = $obj[$temp]['id']; if ($s_id == $s_id2) { return -1; } $query = "select latest_timestamp from stats where s_id = {$s_id}"; $result = $conn->query($query); $resultrow = $result->fetch_assoc(); $json = file_get_contents("https://na.api.pvp.net/api/lol/na/v2.2/matchlist/by-summoner/{$s_id}?seasons=PRESEASON2016&api_key=9073dedb-d0e0-43db-8557-9ae31bf7967e"); $obj = json_decode($json, TRUE); $timestamp = $obj["matches"][0]["timestamp"]; if ($obj["totalGames"] == 0) { return 1; } if ($result->num_rows > 0 && $timestamp > $resultrow["latest_timestamp"] && !empty($obj)) { repopulate($obj, $s_id); } else { if ($result->num_rows == 0) { for ($i = 0; $i < 10; $i++) { $matchid = $obj["matches"][$i]["matchId"]; $championid = $obj["matches"][$i]["champion"]; $timestamp = $obj["matches"][$i]["timestamp"]; populate($matchid, $timestamp, $championid, $s_id); // 1 API request per a call. sleep(1.5); } $query = "select * from wins\n where wins.s_id = {$s_id}\n union\n select * from losses\n where losses.s_id = {$s_id}\n order by timestamp desc"; $results = $conn->query($query); $numrows = $results->num_rows; $latest_timestamp = 0; $kills = 0; $deaths = 0; $assists = 0; $gold = 0; $cs = 0; $resultrow = $results->fetch_assoc(); $latest_timestamp = $resultrow["timestamp"]; $kills = $resultrow["kills"]; $deaths = $resultrow["deaths"]; $assists = $resultrow["assists"]; $gold = $resultrow["gold"]; $cs = $resultrow["cs"]; while ($resultrow = $results->fetch_assoc()) { $kills += $resultrow["kills"]; $deaths += $resultrow["deaths"]; $assists += $resultrow["assists"]; $gold += $resultrow["gold"]; $cs += $resultrow["cs"]; } $kills /= $numrows; $deaths /= $numrows; $assists /= $numrows; $gold /= $numrows; $cs /= $numrows; // Average stats $query = "insert into stats(s_id, latest_timestamp, kills, deaths, assists, gold, cs) \n values({$s_id}, {$latest_timestamp}, {$kills}, {$deaths}, {$assists}, {$gold}, {$cs})"; $result = $conn->query($query); $conn->close(); } } } return $s_id; }
$cs = $resultrow["cs"]; while ($resultrow = $results->fetch_assoc()) { $kills += $resultrow["kills"]; $deaths += $resultrow["deaths"]; $assists += $resultrow["assists"]; $gold += $resultrow["gold"]; $cs += $resultrow["cs"]; } $kills /= $numrows; $deaths /= $numrows; $assists /= $numrows; $gold /= $numrows; $cs /= $numrows; // Average stats $query = "insert into stats(s_id, latest_timestamp, kills, deaths, assists, gold, cs) \n values({$s_id}, {$latest_timestamp}, {$kills}, {$deaths}, {$assists}, {$gold}, {$cs})"; $result = $conn->query($query); $conn->close(); header("Location: stats.php"); } else { $json = file_get_contents("https://na.api.pvp.net/api/lol/na/v2.2/matchlist/by-summoner/{$s_id}?seasons=PRESEASON2016&api_key=9073dedb-d0e0-43db-8557-9ae31bf7967e"); $obj = json_decode($json, TRUE); $timestamp = $obj["matches"][0]["timestamp"]; $query = "select latest_timestamp from stats\n where s_id = {$s_id}"; $result = $conn->query($query); $resultrow = $result->fetch_assoc(); if ($result->numw_rows > 0 && $timestamp > $resultrow["latest_timestamp"] && !empty($obj)) { repopulate($obj, $s_id); } $conn->close(); header("Location: stats.php"); }