Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自php var和其他表的MySQL插入组合_Php_Mysql_Sql - Fatal编程技术网

来自php var和其他表的MySQL插入组合

来自php var和其他表的MySQL插入组合,php,mysql,sql,Php,Mysql,Sql,我试图在我的sql表中插入php变量和另一个表中的1行数据的组合。我找到了相似的例子,但没有一个是这样的组合 在OTHERTABLE.liveDate中,我需要一条记录,但我需要添加一个条件,例如OTHERTABLE中的where id='1' “$navid”、“$loginid”、“$total”、“$where”不是来自其他表 INSERT INTO myTable (`navid`,`loginid`, `pageDisplayNum`, `whereFrom`, `liveDate`)

我试图在我的sql表中插入php变量和另一个表中的1行数据的组合。我找到了相似的例子,但没有一个是这样的组合

在OTHERTABLE.liveDate中,我需要一条记录,但我需要添加一个条件,例如OTHERTABLE中的where id='1' “$navid”、“$loginid”、“$total”、“$where”不是来自其他表

INSERT INTO myTable (`navid`,`loginid`, `pageDisplayNum`, `whereFrom`, `liveDate`) 
VALUES ('$navid', '$loginid', '$total', '$where', 'OTHERTABLE.liveDate')

+我不知道你能做到这一点。我总是插入外键。与使用外键相比,这个答案的优点/缺点是什么?谢谢你的回答,我已经编辑了我的问题$navid'、'$loginid'、'$total'、'$where'不是来自其他表
INSERT INTO myTable (`navid`,`loginid`, `pageDisplayNum`, `whereFrom`, `liveDate`) 
select '$navid', '$loginid', '$total', '$where', OTHERTABLE.liveDate 
from OTHERTABLE
where OTHERTABLE.id='1'