array(2) {
["cwidth"] => array(2) {
[0] => string(5) "593px"
[1] => string(5) "598px"
}
["cheight"] => array(2) {
[0] => string(5) "203px"
[1] => string(5) "111px"
}
}
这保存的是不同行的内容,不能直接保存。
要做成行的形式保存。
$data=array(); //创建临时变量用以存储数据
$length=count($你的array名['cwidth']); //数你有多少行数据
for($i=0; $i<=$length; $i++){ //循环
$data[$i]['cwidth']=$你的array名['cwidth'];
$data[$i]['cheight']=$你的array名['cheight'];
}
出来的数据就像是这样:
array(2){
[0]=>array(2){
['cwidth']=>string(5) "593px"
['cheight']=>string(5) "203px"
}
[1]=>array(2){
['cwidth']=>string(5) "598px"
['cheight']=>string(5) "111px"
}
}
然后再用$db->add($data);插入数据
要做成行的形式保存。
$data=array(); //创建临时变量用以存储数据
$length=count($你的array名['cwidth']); //数你有多少行数据
for($i=0; $i<=$length; $i++){ //循环
$data[$i]['cwidth']=$你的array名['cwidth'];
$data[$i]['cheight']=$你的array名['cheight'];
}
出来的数据就像是这样:
array(2){
[0]=>array(2){
['cwidth']=>string(5) "593px"
['cheight']=>string(5) "203px"
}
[1]=>array(2){
['cwidth']=>string(5) "598px"
['cheight']=>string(5) "111px"
}
}
然后再用$db->add($data);插入数据
温馨提示:答案为网友推荐,仅供参考
第1个回答 2012-11-18
$data=array(2) {
["cwidth"] => array(2) {
[0] => string(5) "593px"
[1] => string(5) "598px"
}
["cheight"] => array(2) {
[0] => string(5) "203px"
[1] => string(5) "111px"
}
}
楼主的这个是二维数组啊,可以改为一维数组就可以插入了
$User = M("User"); // 实例化User对象
$data['cwidth0'] = $data['cwidth'][0];
$data['cwidth1'] = $data['cwidth'][1];
$data['cheight0'] = $data['cheight'][0];
$data['cheight0'] = $data['cheight'][1];
$User->add($data);
这样就可以了,在你二维数组加了个变量$data本回答被网友采纳
["cwidth"] => array(2) {
[0] => string(5) "593px"
[1] => string(5) "598px"
}
["cheight"] => array(2) {
[0] => string(5) "203px"
[1] => string(5) "111px"
}
}
楼主的这个是二维数组啊,可以改为一维数组就可以插入了
$User = M("User"); // 实例化User对象
$data['cwidth0'] = $data['cwidth'][0];
$data['cwidth1'] = $data['cwidth'][1];
$data['cheight0'] = $data['cheight'][0];
$data['cheight0'] = $data['cheight'][1];
$User->add($data);
这样就可以了,在你二维数组加了个变量$data本回答被网友采纳
第2个回答 2012-11-20
$aa = array(2) {
["cwidth"] => array(2) {
[0] => string(5) "593px"
[1] => string(5) "598px"
}
["cheight"] => array(2) {
[0] => string(5) "203px"
[1] => string(5) "111px"
}
}
foreach($aa['cwidth'] as $key => $val){
$data = array();
$data['cwidth'] = $val;
$data['cheight'] = $aa['cheight'][$key];
D('表名')->where("id=$id")->save($data);
}
["cwidth"] => array(2) {
[0] => string(5) "593px"
[1] => string(5) "598px"
}
["cheight"] => array(2) {
[0] => string(5) "203px"
[1] => string(5) "111px"
}
}
foreach($aa['cwidth'] as $key => $val){
$data = array();
$data['cwidth'] = $val;
$data['cheight'] = $aa['cheight'][$key];
D('表名')->where("id=$id")->save($data);
}