我的数据现在以下面所述的格式存储在json中,实际上是类别,项目和费率的单独数组。但是我希望它按照选择的类别进行存储。如果选择了类别1,则必须显示该类别下的项目数和每个项目的费率。
目前我的JSON订单如下:
{"level":{"Primary":"1","Upper Secondary":"2"},"sub":{"2":"bm","1":"maths"},"rate2":{"bm":"10","bi":"20","maths":"30"},"submit":"submit"}
$_SESSION['info'][$level]=array('level'=>$level,array('subject'=>$subject,'rate'=>$rate));
如何在SESSION数组中按以下顺序正确排列:
Primary
[bm=10
,bi=20]
Upper Secondary
[maths=30]
如何在解码之后将其解码,如下所示在php文件中存储到数据库中?
$return = $_POST;
$return["json"] = json_encode($return);
表单输入:
<ul class="small-block-grid-3 medium-block-grid-3 large-block-grid-2">
<li><input type="checkbox" name="level[Primary]" id="level" class="level" value="1"><label>Primary</label></li>
<li><input type="checkbox" name="level[Upper Secondary]" id="level" class="level" value="2"><label>Upper Secondary</label></li>
<li><input type="checkbox" name="level[University]" id="level" class="level" value="3"><label>University</label></li>
<li><input type="checkbox" name="level[Lower Secondary]" id="level" class="level" value="4"><label>Lower Secondary</label></li>
<li><input type="checkbox" name="level[Pre University]" id="level" class="level" value="5"><label>Pre University</label></li>
<li><input type="checkbox" name="level[Skills/Languages]" id="level" class="level" value="6"><label>Skills/Languages</label></li>
</ul>
//下面是while循环,当使用ajax //
从数据库获取数据时echo '<table><tr><td>'. $subjects . '</td><td><input type="checkbox" name="sub['.$levels_id.']" id="sub" value="'.$subjects.'"></td>';
echo'<td><input type="textbox" name="rate2['.$subjects.']" class="rate2" value="" id="'.$subjects.'"></td></tr></table>';