Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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 拆分.serialize()的输出,并为每个拆分的部分创建insert语句_Php_Jquery_Sql_Split - Fatal编程技术网

Php 拆分.serialize()的输出,并为每个拆分的部分创建insert语句

Php 拆分.serialize()的输出,并为每个拆分的部分创建insert语句,php,jquery,sql,split,Php,Jquery,Sql,Split,我有3个表和一个来自.serialize()的输出字符串 表1: 表2: 表3: .serialize()输出: 4=Test&6=This is a test&9=19&15=Bla Bla Bla&appid=19746 4 = parameterid, Test=parametervalue, appid=19746 对于序列化输出的每个“部分”,我想做一个INSERT语句,它将parameterid、appid和parametervalue添加到表pa

我有3个表和一个来自
.serialize()
的输出字符串

表1:

表2:

表3:

.serialize()
输出:

4=Test&6=This is a test&9=19&15=Bla Bla Bla&appid=19746

4 = parameterid, Test=parametervalue, appid=19746
对于序列化输出的每个“部分”,我想做一个
INSERT
语句,它将
parameterid
appid
parametervalue
添加到表
parametervalue
中。如何拆分并动态添加它?“拆分”应使用PHP完成。

使用:

输出:

Array
(
    [4] => Test
    [6] => This is a test
    [9] => 19
    [15] => Bla Bla Bla
    [appid] => 19746
)
现在,要执行
插入操作
,您可以在分割的数组中循环:

foreach ($result as $part) {
    // do the INSERT
}

ID错误。在您的SO答案中,它们是0-4,在示例中,它们是正确的
参数化ID
s:)@doonot:啊,您是对的。我错过了。我现在编辑了我的答案以反映这一点。谢谢
4=Test&6=This is a test&9=19&15=Bla Bla Bla&appid=19746

4 = parameterid, Test=parametervalue, appid=19746
$str = '4=Test&6=This is a test&9=19&15=Bla Bla Bla&appid=19746';
$result = array();
parse_str($str, $result);
print_r($result);
Array
(
    [4] => Test
    [6] => This is a test
    [9] => 19
    [15] => Bla Bla Bla
    [appid] => 19746
)
foreach ($result as $part) {
    // do the INSERT
}