dqfr90979 2014-10-07 09:43
浏览 36
已采纳

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

$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'];
            }

}

This is my code right now. I need to insert a row in 3 brackets tables with the the value of ID (is AUTO_INCREMENT) from leagues tables.

normally i do like this, but now I dont know what I must put to replace $id in values.

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')");

What should I do?

  • 写回答

1条回答 默认 最新

  • doufeinai6081 2014-10-07 10:18
    关注

    Well, I found the answer :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')");
             }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)