我已经用 PHP 制作了一个表单应用程序,现在我正在尝试实现更新字段。我已经做到了,所以 POST 包含这样的数据:
Array (
'17-label' => "select label 0 ",
'17-placeholder' => "select placeholder 0 ",
'17-answer' => Array (
"Answer 1",
"Answer 2",
"Answer 3"
),
'18-label' => "textfield label 1",
'18-placeholder' => "textfield placeholder 1",
'19-label' => "textfield label 2",
'19-placeholder' => "textfield placeholder 2"
)
现在如您所见,我使用要更新的行的 ID 作为开始,然后使用 - 来标识分隔符和我要在列中更新的实际列名。
但是我该怎么做呢?
我知道如何更新,只是如何确保所有内容都进入正确的列。第一个数字是 id,在 - 符号之后是实际的列名。但我该怎么做呢?
最佳答案
我不完全确定我已经理解,但如果它正在分解并使用数组键的组成部分,那么也许这可能有用
foreach( $arr as $key => $str ){
list( $id,$dash,$param )=explode( '-', $key );
/* How do you wish to handle sub-arrays? */
if( is_array( $param ) && !empty( $param ) )$param=implode(',',$param);
/* do stuff with ID and PARAM */
}
或者,可能更像是:
foreach( $arr as $key => $value ){
list( $id, $dash, $param )=explode( '-', $key );
if( is_array( $value ) && !empty( $value ) )$value=implode(',',$value);
/* do stuff with ID and PARAM and value */
}
关于php - 通过 POST 名称中的 id 对 POST 数据进行排序以更新 MySQL 表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47649804/