public static function trainAnts($ants) { while (!empty($ants)) { $name = key($ants); $shift = array_shift($ants); if (empty($shift)) { continue; } $ant = Ants::getAntByName($name)->fetch_all()[0]; Ants::tryTrain($ant, $shift); $userID = User::getUserById($_SESSION['id'])['iduser']; $db = mysqli_connect("localhost", "root", "1234", "ant_rpg"); $result = mysqli_query($db, "INSERT INTO train_ants (ant_id,user_id,quantity,trained) VALUES ('" . $ant[0] . "','" . $userID . "','" . $shift . "',0)"); } }