我有这个我正在尝试更新的数组
$arr = array(
'one' => array(
'slidertitle' => 'lorem ipsum',
'sliderlocation' => 'http://localhost/images/1.jpg',
'sliderdescription' => 'this is a good lorem ipsum image',
'sliderposition' => 1
),
'two' => array(
'slidertitle' => 'second slider',
'sliderlocation' => 'http://localhost/images/2.jpg',
'sliderdescription' => 'this space was reserved for a link source code here',
'sliderposition' => 2
),
'three' => array(
'slidertitle' => 'third slider',
'sliderlocation' => 'http://localhost/images/3.jpg',
'sliderdescription' => 'this is a third slider by name only',
'sliderposition' => 3
),
'four' => array(
'slidertitle' => 'fourth slider',
'sliderlocation' => 'http://localhost/images/4.jpg',
'sliderdescription' => 'fourth slider has a description',
'sliderposition' => 4
),
'five' => array(
'slidertitle' => 'fifth slider',
'sliderlocation' => 'http://localhost/images/5.jpg',
'sliderdescription' => 'a slider on rails is really nice',
'sliderposition' => 5
),
'six' => array(
'slidertitle' => 'sixth slider',
'sliderlocation' => 'http://localhost/images/6.jpg',
'sliderdescription' => 'this is the sixth slider,like,really!',
'sliderposition' => 6
)
);
使用从表单发布的数据。我没有通过$ _POST数据进行清理,因为它只是一个例子。
$clickedButton = $_POST['clickedButton'];
$sliderKey = $_POST['sliderKey'];
$sliderTitle = $_POST['sliderTitle'];
$sliderDescription = $_POST['sliderDescription'];
$sliderLocation = $_POST['sliderLocation'];
$sliderPosition = $_POST['sliderPosition'];
$result = mysql_query("SELECT * FROM arr");
$row = mysql_fetch_array($result);
$data = $row['encoded_array'];
//echo $data.'<br/>'.'<br/>';
$unserialized = unserialize($data);
$unserialized[$sliderKey]["slidertitle"] = $sliderTitle;
$unserialized[$sliderKey]["sliderlocation"] = $sliderLocation;
$unserialized[$sliderKey]["sliderdescription"] = $sliderDescription;
$unserialized[$sliderKey]["sliderposition"] = $sliderPosition;
//print_r($unserialized);
$newSerialize = serialize($unserialized);
mysql_query("UPDATE arr SET encoded_array = '$newSerialize'");
当我print_r $unserialized
时,我刚发布的数据就在那里,但是在我序列化之后没有提交到数据库。我有什么问题吗?
修改
我的数组中有两条记录,这是我在保存之前得到的
a:2:{s:13:"5056d218631bc";a:4:{s:11:"slidertitle";s:5:"lorem";s:14:"sliderlocation";s:5:"ipsum";s:17:"sliderdescription";s:11:"hello world";s:14:"sliderposition";i:3;}s:13:"5056db269305c";a:4:{s:11:"slidertitle";s:1:"A";s:14:"sliderlocation";s:6:"RECORD";s:17:"sliderdescription";s:18:"WITH A DESCRIPTION";s:14:"sliderposition";s:1:"2";}}
序列化:
Array
(
[5056d218631bc] => Array
(
[slidertitle] => lorem
[sliderlocation] => ipsum
[sliderdescription] => hello world
[sliderposition] => 3
)
[5056db269305c] => Array
(
[slidertitle] => A
[sliderlocation] => RECORD
[sliderdescription] => WITH A DESCRIPTION
[sliderposition] => 2
)
)
答案 0 :(得分:0)
@alfasin @AdamGold @Poonam @Jaitsu我真的应该得到一些谴责发布这个,但问题是我在执行保存的功能后错过了一个休息时间:
这就是我之前的事情
$x = $_POST['clickedButton'];
switch ($x)
{
case 'newSave':
newSave();
break;
case 'editSave':
editSave();
;
case 'editDelete':
editDelete();
;
break;
default:
echo "Some click";
}
这就是我现在的工作原理
$x = $_POST['clickedButton'];
//echo $x;
switch ($x)
{
case 'newSave':
newSave();
break;
case 'editSave':
editSave();
;
break;
case 'editDelete':
editDelete();
;
break;
default:
echo "Some click";
}
感谢您的耐心和贡献。