if isset _POST add_stat Заносим результаты всех матчей for _POST count

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
if (isset($_POST["add_stat"])) {
//Заносим результаты всех матчей
for ($i=1; $i<=$_POST["count"]; $i++) {
$match = $pdo->prepare("SELECT player FROM statistica WHERE player=".$_POST["name$i"]." and id_match=".$_GET['static']."");
$match->execute();
$playermatch = $match->fetch(PDO::FETCH_NUM);
if ($_POST["name$i"] == $playermatch[0]) {
//obnova
echo "<tr><td style='text-align: center; color: red;'>Вы уже занесли данные ЭТОГО игрока за ЭТОТ матч!</td></tr>";
} else {
$data = array();
$data['player'] = $_POST["name$i"];
$data['id_match'] = $_GET["static"];
$data['osnova'] = $_POST["osnova$i"];
$data['turnir'] = $row["turnir"];
$data['zamena'] = $_POST["zamena$i"];
$data['minuta'] = $_POST["minuta$i"];
$data['fols'] = $_POST["fols$i"];
$data['myfols'] = $_POST["folsmy$i"];
$data['otbor'] = $_POST["otbor$i"];
$data['udar'] = $_POST["udar$i"];
$data['udarvstvor'] = $_POST["udarvstvor$i"];
$data['golpass'] = $_POST["golpass$i"];
$data['gol'] = $_POST["gol$i"];
$data['otbil'] = $_POST["otbil$i"];
$data['propustil'] = $_POST["propusk$i"];
$data['ozenka'] = $_POST["ozenka$i"];
$data['sezon'] = $_POST["sezon"];
$STH = $pdo->prepare("INSERT INTO statistica (player, id_match, turnir, osnova, zamena, minuta, fols, myfols, otbor, udar, udarvstvor, golpass, gol, otbil, propustil, ozenka, sezon) values (:player, :id_match, :turnir, :osnova, :zamena, :minuta, :fols, :myfols, :otbor, :udar, :udarvstvor, :golpass, :gol, :otbil, :propustil, :ozenka, :sezon)");
$STH->execute($data);
echo "<tr><td style='text-align: center;'>Добавили!</td></tr>";
echo "<tr><td style='text-align: center;'>Продолжаем, на очереди последний этап - <a href='admin.php?info=$_GET[static]'>Следующий этап...</a></td></tr></table>";
}
}
//Добавляем статистику после каждого матча в общую
for ($i=1; $i<=$_POST["count"]; $i++) {
$match1 = $pdo->prepare("SELECT player FROM stat_team WHERE player=".$_POST["name$i"]." and turnir='$row[turnir]' and sezon='$row[sezon]'");
$match1->execute();
$statement = $pdo->query("SELECT AVG(ozenka) as average FROM statistica WHERE player='".$_POST["name$i"]."' and turnir='$row[turnir]' and sezon='$row[sezon]'");
$result = $statement->fetchObject();
$average = $result->average;
$playermatchh = $match1->fetch(PDO::FETCH_NUM);
if ($_POST["name$i"] == $playermatchh[0]) {
if($_POST["osnova$i"] == 'yes'){
$players = $pdo->prepare("UPDATE stat_team SET igra=(igra+1), osnova=(osnova+1), minuta=(minuta+'".$_POST["minuta$i"]."'), fols=(fols+'".$_POST["fols$i"]."'), myfols=(myfols+'".$_POST["folsmy$i"]."'), otbor=(otbor+'".$_POST["otbor$i"]."'), udar=(udar+'".$_POST["udar$i"]."'), udarvstvor=(udarvstvor+'".$_POST["udarvstvor$i"]."'), golpass=(golpass+'".$_POST["golpass$i"]."'), gol=(gol+'".$_POST["gol$i"]."'), otbil=(otbil+'".$_POST["otbil$i"]."'), propustil=(propustil+'".$_POST["propusk$i"]."'), sezon='".$_POST["sezon"]."', ozenka='$average' WHERE player='".$_POST["name$i"]."' and turnir='$row[turnir]' and sezon='$row[sezon]' LIMIT 1");
$players->execute();
}
if($_POST["zamena$i"] == 'yes') {
$players1 = $pdo->prepare("UPDATE stat_team SET igra=(igra+1), zamena=(zamena+1), minuta=(minuta+'".$_POST["minuta$i"]."'), fols=(fols+'".$_POST["fols$i"]."'), myfols=(myfols+'".$_POST["folsmy$i"]."'), otbor=(otbor+'".$_POST["otbor$i"]."'), udar=(udar+'".$_POST["udar$i"]."'), udarvstvor=(udarvstvor+'".$_POST["udarvstvor$i"]."'), golpass=(golpass+'".$_POST["golpass$i"]."'), gol=(gol+'".$_POST["gol$i"]."'), otbil=(otbil+'".$_POST["otbil$i"]."'), propustil=(propustil+'".$_POST["propusk$i"]."'), sezon='".$_POST["sezon"]."', ozenka='$average' WHERE player='".$_POST["name$i"]."' and turnir='$row[turnir]' and sezon='$row[sezon]' LIMIT 1");
$players1->execute();
}
} else {
if($_POST["osnova$i"] == 'yes') { $osnovaa=1; $zamenaa=0; }
if($_POST["zamena$i"] == 'yes') { $zamenaa=1; $osnovaa=0; }
$data1 = array();
$data1['player'] = $_POST["name$i"];
$data1['turnir'] = $row["turnir"];
$data1['minuta'] = $_POST["minuta$i"];
$data1['fols'] = $_POST["fols$i"];
$data1['myfols'] = $_POST["folsmy$i"];
$data1['otbor'] = $_POST["otbor$i"];
$data1['udar'] = $_POST["udar$i"];
$data1['udarvstvor'] = $_POST["udarvstvor$i"];
$data1['golpass'] = $_POST["golpass$i"];
$data1['gol'] = $_POST["gol$i"];
$data1['otbil'] = $_POST["otbil$i"];
$data1['propustil'] = $_POST["propusk$i"];
$data1['ozenka'] = $playerr["ozenkaa"];
$data1['sezon'] = $_POST["sezon"];
$STH1 = $pdo->prepare("INSERT INTO stat_team (player, turnir, osnova, zamena, minuta, fols, myfols, otbor, udar, udarvstvor, golpass, gol, otbil, propustil, ozenka, sezon)
values (:player, :turnir, $osnovaa, $zamenaa, :minuta, :fols, :myfols, :otbor, :udar, :udarvstvor, :golpass, :gol, :otbil, :propustil, :ozenka, :sezon)");
$STH1->execute($data1);
}
}
for ($i=1; $i<=$_POST["count"]; $i++) {
//Записываем рейтинг игроков
$match_rating = $pdo->prepare("SELECT player FROM rating WHERE player=".$_POST["name$i"]." and sezon='$row[sezon]'");
$match_rating->execute();
$statement = $pdo->query("SELECT AVG(ozenka) as average FROM statistica WHERE player='".$_POST["name$i"]."' and sezon='$row[sezon]'");
$result = $statement->fetchObject();
$average = $result->average;
$ratingg = $match_rating->fetch(PDO::FETCH_NUM);
if ($_POST["name$i"] == $ratingg[0]) {
$ratin = $pdo->prepare("UPDATE rating SET rating=$average WHERE player='".$_POST["name$i"]."' and sezon='$row[sezon]' LIMIT 1");
$ratin->execute();
} else {
$dataa = array();
$dataa['player'] = $_POST["name$i"];
$dataa['sezon'] = $_POST["sezon"];
$dataa['rating'] = $average;
$rat = $pdo->prepare("INSERT INTO rating (player, sezon, rating) values (:player, :sezon, :rating)");
$rat->execute($dataa);
}
}
}
}