public static function sendArmy($x, $y, $ants) { $xCord = Nest::getNestCords($_SESSION['nestid']); $diff = abs($x - $xCord); $defenderId = User::getUserByMapCords($x, $y)[0][0]; $db = mysqli_connect("localhost", "root", "1234", "ant_rpg"); mysqli_query($db, "INSERT INTO attack (attacker_id,defender_id,cordinateDiffrence) VALUES ('" . $_SESSION['id'] . "','" . $defenderId . "','" . $diff . "')"); $request = mysqli_query($db, "SELECT * FROM attack Where attacker_id = " . $_SESSION['id'] . " order by idattack desc Limit 1"); $battleId = $request->fetch_all()[0][0]; for ($i = 0; $i < 2; $i++) { if (empty($ants[$i])) { continue; } mysqli_query($db, "INSERT INTO troops_for_battle (ant_id,quantity,battleid) VALUES ('" . ($i + 1) . "','" . $ants[$i] . "','" . $battleId . "')"); Ants::updateAnts($i + 1, $ants[$i]); } }