从请愿中获取用户ID并插入其他表中

时间:2013-02-27 10:43:02

标签: mysql database

帮助我如何从这个表中获取用户id,例如petition_id = 52然后如果得到所有user_id我想插入SYSTEMID中的第二个表(auto_increment)

这是我的命令:

$result = $db->Execute("SELECT petition_id,MT4ACCOUNTID, phpfox_petition_text.petition_goal,user_id  " . "from phpfox_petition_text,phpfox_tradeusers " . "where  phpfox_petition_text.petition_goal = $mt4acctid and user_id=$systemid ");
        $symbol1 = $result->fields[0];
        $symbol14 = $result->fields[3];

$result212 = $db->Execute("SELECT petition_id, user_id " . "from phpfox_petition_sign " . "where  petition_id=".$symbol1." and MT4ACCOUNTID=$mt4acctid ORDER BY time_stamp DESC");
  $symbol122 = $result212->fields[1];

  $result111 = $db->Execute("SELECT full_name  " . "from phpfox_user " . "where  user_id=$systemid ");
        $symbol1user = $result111->fields[0];


        $record = array();
        $record["SYMBOL"] = $symbol;
        $record["CMD"] = $cmd;
        $record["VOLUME"] = $volume;
        $record["PRICE"] = $price;
        $record["SLIPPAGE"] = $slippage;
        $record["STOPLOSS"] = $stoploss;
        $record["TAKEPROFIT"] = $takeprofit;
        $record["COMMENT"] = 'MyfaceFx>Copied from ::'.$symbol1user;
        $record["MAGIC"] = $magic;
        $record["EXPIRATION"] = $expiration;
        $record["MT4SIGNALID"] = $signalid;
        $record["BROKERNAME"] = $brokername;
        $record["MT4ACCTID"] = $mt4acctid;
        $record["TIMESTAMP"] = time();
        $record["SYSTEMID"] =$symbol122;
        $record["ORDERUNITS"] = $basecurrencyunits;
        $record["ACCTBALANCE"] = $acctbalance;
        $record["ACCTCURRENCY"] = $acctcurrency;

    $insertSQL = $db->AutoExecute('phpfox_tradesignals', $record, 'INSERT');
    $insertsignalid = $db->Insert_ID();

它的工作,但只得到1个这样的结果:

   expiration : systemid       
    ...............................................................

              : 27 


但我希望得到这样的结果:

   expiration : systemid       
    ...............................................................

              : 27 

              : 29 

              : 26

              : 34
 etc....

表格提示

   petition_id : user_id        
    ...............................................................
    50       : 35   
    52       : 27 
    40       : 23  
    52       : 29 
    50       : 35   
    52       : 26
    40       : 23  
    52       : 34
   etc....

表SYSTEMID

   expiration : systemid       
    ...............................................................

1 个答案:

答案 0 :(得分:0)

因此,如果您想将一个表中的值插入另一个表中:

INSERT INTO table2 (systemid)
SELECT user_id
FROM   table1
WHERE  petition_id = 52