更新しようとしているこの配列があります
$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
が投稿したばかりのデータはそこにありますが、シリアル化した後にデータベースにコミットされません.私が間違っていることはありますか?.
編集:
配列に 2 つのレコードがあり、これが保存前に得られるものです
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
)
)