Php 拆分.serialize()的输出,并为每个拆分的部分创建insert语句
我有3个表和一个来自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
.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
}