[英]Using one Array Value As Another Array Key PHP MySQL
I want to use a value from one array as the key for another as part of a MySQL replace statement. 我想将一个数组中的值用作另一个替换项的键,作为MySQL replace语句的一部分。 I tried the code below but got a syntax error of
我尝试了以下代码,但语法错误为
"Unexpected '[' expected ']'"
Can this be done and if so any help with the right syntax would bemuch appreciated. 可以做到这一点,如果可以的话,请提供有关正确语法的任何帮助。
$sql = "REPLACE INTO sections(IDENTIFIER, NAME, DESCRIPTION, SEQUENCE, INSTRUCTIONS, TIME_AVAILABLE, EXTERNAL_RESOURCE)
VALUES ('$currentline[$flippedheaders['IDENTIFIER']]', '$currentline[flippedheaders['NAME']]', '$currentline[flippedheaders['DESCRIPTION']]', $currentline[flippedheaders['SEQUENCE']], '$currentline[flippedheaders['INSTRUCTION']]', $currentline[flippedheaders['TIME_AVAILABLE']], '$currentline[flippedheaders['EXTERNAL_RESOURCE']]')";
I see you have a lot of typos there, mising quotes and not properly interpolating the string. 我看到您那里有很多错别字,误导了引号,并且没有正确地插入字符串。 Try as follows:
尝试如下:
$sql = "REPLACE INTO sections(IDENTIFIER, NAME, DESCRIPTION, SEQUENCE, INSTRUCTIONS, TIME_AVAILABLE, EXTERNAL_RESOURCE)
VALUES ('{$currentline[$flippedheaders['IDENTIFIER']]}', '{$currentline[$flippedheaders['NAME']]}', '{$currentline[$flippedheaders['DESCRIPTION']]}', '{$currentline[$flippedheaders['SEQUENCE']]}, '{$currentline[$flippedheaders['INSTRUCTION']]}', '{$currentline[$flippedheaders['TIME_AVAILABLE']]}', '{$currentline[$flippedheaders['EXTERNAL_RESOURCE']]}')";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.