0

我有这个数组,我正在尝试更新

$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
        )

)
4

1 回答 1

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";
}

我感谢您的耐心和贡献。

于 2012-09-17T08:59:03.523 回答