<label><input type="checkbox" id="1" name="post[tpl]" value="1" />首页</label>
<label><input type="checkbox" id="2" name="post[tpl]" value="2" />列表页</label>
<label><input type="checkbox" id="3" name="post[tpl]" value="3" />内容页</label>
当我只勾选了,首页 post[tpl]=1 时,那么就代表 postdb[css][index] 有写数据,没勾选代表没写数据,在存储的时候,只存储勾选的,
如果全部勾选了,那么下面三个数据并成一个数据放到字段中,如果都没勾选,那就是空!请大虾帮忙这段怎么写? 怎么去控制数组
<textarea name="postdb[css][index]" rows="5" cols="120"></textarea>
<textarea name="postdb[css][list]" rows="5" cols="120"></textarea>
<textarea name="postdb[css][bencandy]" rows="5" cols="120"></textarea>
这是我的存储格式!
$postdb[css][email protected]($postdb[css]);
最后的会把结果 $postdb[css]放到数据库字段中
------解决方案--------------------
<input type="checkbox" id="1" name="post[tpl]" value="1" />
改成
<input type="checkbox" id="1" name="post[tpl][]" value="1" />
后,php端$_POST['post']['tpl'] 就是一个数组了,然后遍历控制$_POST['postdb']['css'] 就是了。
------解决方案--------------------
name="post[tpl]" 应写作 name="post[tpl][]"
否则只能接收到单值
$d = array(1 => 'index', 2 => 'list', 3 => 'bencandy');
foreach($_POST['post']['top'] as $k) {
$postdb['css'][$d[$k]] = $_POST['postdb']['css'][$d[$k]];
}