【发布时间】:2011-11-19 08:20:39
【问题描述】:
我使用 codeigniter。如何通过json_encode 将此值(在 html 代码中)插入数据库行?
演示: http://jsfiddle.net/AQPwv/3/
<input name="name_r[0][]" value="hi">
<p>
<input name="units[1][]" value="how">
<input type="text" name="units[1][]" value="2" style="width:20px;">
<input type="text" name="units[1][]" value="256314" style="width:65px;">
<input name="units[1][]" value="fine">
<input type="text" name="units[1][]" value="4" style="width:20px;">
<input type="text" name="units[1][]" value="854621" style="width:65px;">
<p>
<input type="text" name="price_change[2][]" value="21466" style="width:75px;">
<input type="text" name="price_change[2][]" value="54219" style="width:75px;">
<input type="text" name="price_change[2][]" value="48752" style="width:65px;">
<input type="text" name="price_change[2][]" value="86541" style="width:75px;">
<input type="text" name="price_change[2][]" value="47276" style="width:75px;">
<input type="text" name="price_change[2][]" value="74538" style="width:65px;">
<p>
<hr>
<p>
<input name="name_r[0][]" value="hello">
<p>
<input name="units[1][]" value="Library">
<input type="text" name="units[1][]" value="5" style="width:20px;">
<input type="text" name="units[1][]" value="95641" style="width:65px;">
<input name="units[1][]" value="khobee">
<input type="text" name="units[1][]" value="6" style="width:20px;">
<input type="text" name="units[1][]" value="84527" style="width:65px;">
<input name="units[1][]" value="PowerTools ">
<input type="text" name="units[1][]" value="7" style="width:20px;">
<input type="text" name="units[1][]" value="75462" style="width:65px;">
<p>
<input type="text" name="price_change[2][]" value="8457" style="width:75px;">
<input type="text" name="price_change[2][]" value="134" style="width:75px;">
<input type="text" name="price_change[2][]" value="76144" style="width:65px;">
<input type="text" name="price_change[2][]" value="956414" style="width:75px;">
<input type="text" name="price_change[2][]" value="7546" style="width:75px;">
<input type="text" name="price_change[2][]" value="123" style="width:65px;">
<input type="text" name="price_change[2][]" value="84541" style="width:75px;">
<input type="text" name="price_change[2][]" value="654" style="width:75px;">
<input type="text" name="price_change[2][]" value="8165" style="width:65px;">
<input type="text" name="price_change[2][]" value="2145" style="width:75px;">
<input type="text" name="price_change[2][]" value="354" style="width:75px;">
<input type="text" name="price_change[2][]" value="4774" style="width:65px;">
更新: 我想将数据存储在数据库表中:
[{
"name_r": "hi",
"units": ["how", "2", "256314"],["fine", "4", "854621"],
"price_change": ["21466", "54219", "48752"],["86541", "47276", "74538"],
}, {
"name_r": "hello",
"units": ["Library", "5", "95641"],["khobee", "6", "84527"],["PowerTools ", "7", "75462"],
"checkbox_units": ["8457", "134", "76144"],["956414", "7546", "123"],["84541", "654", "8165"],["2145", "354", "4774"]
}]
怎么样?
【问题讨论】:
-
不确定我是否遵循您的问题。为什么要使用 json_encode?您想在数据库的一个字段中插入所有信息吗?还是您希望每条信息位于不同的字段中?
-
如果你看到 html 代码找到答案这个问题(你为什么要使用 json_encode?)。我有 2 个具有不同值的 html 模拟。我想在您数据库的一个字段中插入所有信息。您有什么建议?
-
我建议你不要在一个字段中插入所有信息。
-
如果你想使用支持json类型的数据库,你可以使用MongoDB(mongodb.org/display/DOCS/Introduction)
-
@Alfwed 所有信息都是相关的。目前还不清楚用户注册了几个html。它是动态的。不过,你有什么意见?
标签: php arrays codeigniter json