【发布时间】:2016-09-29 07:46:25
【问题描述】:
我有需要插入 MySQL 表的 JSON。
我已经做的是,使用以下方法将其转换为数组:
$json_data = json_decode($geo_json, true);
并得到数组的输出,但我不知道如何插入第二个和第三个 MySQL 表。
我的 MySQL 表:
表一:
geo_id | user_id | geo_title | geo_description | geo_date |geo_status |geo_action |action_reason | geo_json | remote_ip | map_type |geo_snapshot
我可以轻松插入上表,但问题在下面列出的表二和表三中。
表2:
id | layer_id | map_id | layer_name | user_id | draw_type | latlng | radious
表3:
data_id | geo_key | geo_value | map_id | layer_id
我得到的数组:
Array
(
[type] => FeatureCollection
[features] => Array
(
[0] => Array
(
[type] => Feature
[properties] => Array
(
[action] => a
[poi_name] => a
[fac_type] => 17
[ph_number] => a
[hno] => a
[postcode] => a
[mail] => a
[str_nm] => a
[photo] => developer-page.png
[comment] => a
[url] => a
[sub_loc] => a
[employee] => a
)
[geometry] => Array
(
[type] => Point
[coordinates] => Array
(
[0] => 88.434448242188
[1] => 22.510971144638
)
)
)
[1] => Array
(
[type] => Feature
[properties] => Array
(
[action] => b
[poi_name] => b
[fac_type] => 18
[ph_number] => b
[hno] => b
[postcode] => b
[mail] => b
[str_nm] => b
[photo] => 1475131600_developer-page.png
[comment] => b
[url] => b
[sub_loc] => b
[employee] => b
)
[geometry] => Array
(
[type] => Point
[coordinates] => Array
(
[0] => 88.321151733398
[1] => 22.50906814933
)
)
)
)
)
现在的问题是将以上数据插入两个单独的表中:
表2:这只需要从上面的php数组中插入draw_type | latlng。
示例:draw_ type: point and latlng : coordinates
表 3:
这需要从 PHP 数组上方插入 geo_key | geo_value | map_id | layer_id。
示例:
geo_key : properties [action,poi_name,fac_type,ph_number,hno,postcode,mail,str_nm, photo, comment, url, sub_loc, employee]
geo_value : [properties values ]
map_id :[this will be table 1 insert id]
layer_id : [this can be blank]
请指导我并告诉我如何开始。
【问题讨论】:
-
您是问如何通过提供特定的索引值从数组中提取数据?
-
你知道如何使用
foreach语句吗? -
@HZS 我想知道如何将上述数组数据插入到 MySQL 三个不同的表中作为提及字段。您可以看到三个不同的表,采用不同的方法。第三个表只接受键:值数据。
-
@RiggsFolly 我知道 foreach 声明。请在此处使用示例向我展示 foreach 语句如何提供帮助。
-
这不是 SO 的工作方式。您向我们展示您的尝试,告诉我们您在哪里遇到问题,我们会帮助解决该问题。 我们不按照规范工作所以不是免费的编码服务