为新表添加另一行时,在 3 个表中插入一行


insert a row in 3 tables when adding another row for a new table

$fcname = isset($_POST["name"]) ? $_POST["name"] : "";
$fcshortname = isset($_POST["shortname"]) ? $_POST["shortname"] : "";
$fctext = isset($_POST["text"]) ? $_POST["text"] : "";
$fcfullimg = isset($_FILES["fullimg"]) ? $_FILES["fullimg"] : "";
$fccountry = isset($_POST["country"]) ? $_POST["country"] : "";
$fcgame = isset($_POST["game"]) ? $_POST["game"] : "";
$fcfirst = isset($_POST["first"]) ? $_POST["first"]: "";
$fcsecond = isset($_POST["second"]) ? $_POST["second"] : "";
$fcthird = isset($_POST["third"]) ? $_POST["third"] : "";
$fcgroups = isset($_POST["groups"]) ? $_POST["groups"] : "";
$fcngroups = isset($_POST["ngroups"]) ? $_POST["ngroups"] : "";
$fcbrackets = isset($_POST["brackets"]) ? $_POST["brackets"] : "";
$fcnbrackets = isset($_POST["nbrackets"]) ? $_POST["nbrackets"] : "";
$fcbracketsmode = isset($_POST["bracketsmode"]) ? $_POST["bracketsmode"] : "";
$new_window = isset($_POST['new_window']) ? 1 : 0;
if(isset($_POST['safe'])) {
$query = safe_query("INSERT INTO `".PREFIX."leagues` (`name`, `shortname`, `addedon`, `text`, `fullimg`, `country`, `game`, `first`, `second`, `third`, `groups`, `ngroups`, `brackets`, `nbrackets`, `bracketsmode`, `sortid`, `activated`, `new_window`) VALUES ('$fcname', '$fcshortname', NOW(), '$fctext', '$fullimg_name', '$fccountry', '$fcgame', '$fcfirst', '$fcsecond', '$fcthird', '$fcgroups', '$fcngroups', '$fcbrackets', '$fcnbrackets', '$fcbracketsmode', '$sortid', 1, $new_window )");
            if($query) {
                redirect('admincenter.php?site=leagues',$_language->module['fc_added'],2);
            } else {
                echo $_language->module['fc_added_error'];
            }
}

这是我现在的代码。我需要在 3 个括号表中插入一行,其中包含排行表中的 ID(是 AUTO_INCREMENT(的值。

通常我喜欢这样,但现在我不知道我必须用什么来替换$id值。

safe_query("INSERT INTO `".PREFIX."brackets4` (`league`) VALUES ('$id')");
safe_query("INSERT INTO `".PREFIX."brackets8` (`league`) VALUES ('$id')");
safe_query("INSERT INTO `".PREFIX."brackets16` (`league`) VALUES ('$id')");

我该怎么办?

好吧,我找到了答案:D

$quera = mysql_query("SELECT id FROM `".PREFIX."leagues` ORDER BY id DESC LIMIT 1");
         while($res = mysql_fetch_array($quera)) {
               $ida = $res['id'];
               safe_query("INSERT INTO `".PREFIX."brackets4` (`league`) VALUES ('$ida')");
               safe_query("INSERT INTO `".PREFIX."brackets8` (`league`) VALUES ('$ida')");
               safe_query("INSERT INTO `".PREFIX."brackets16` (`league`) VALUES ('$ida')");
         }