如何保存多个重复字段作为数据库阵列? [英] How to save multiple repeatable fields as array in database?

查看:132
本文介绍了如何保存多个重复字段作为数据库阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在主题进出口工作我试图做的幻灯片。我所拥有的一切设定到目前为止,我只是不知道如何将它们保存在数据库中,当有多个幻灯片。

我会跳过code,因为它是非常大的病只需要添加例如输入值。

每个幻灯片由图片上传领域(这基本上是文本字段保存链接图像)和textarea的领域在幻灯片中的文字。

所以滑动值都是这样的。

 幻灯片1  - > $幻灯片[图片] [0]  -  $幻灯片[文] [0]幻灯片2  - > $幻灯片[图片] [1]  -  $幻灯片[文字] [1]滑动3  - > $幻灯片[图片] [2]  -  $幻灯片[文] [2]

这是一个字preSS主题等等字preSS它自身能够保存一个数组时,它承认它。如果有人是熟悉的主题是建立在选项框架构建的。

当我保存这个,这是我在数据库中获取。

  A:1:{S:13:slide_example;一:1:{S:5:形象; S:0:;}}

在(我猜的)应该是这样的。

  A:1:{S:13:slide_example;一:1:{S:5:形象; S:0:幻灯片文本;};一:2:{S:5:形象; S:0:幻灯片文本;};一:3:{S:5:形象; S:0:幻灯片文本;}}


解决方案

我做了它的工作。林不知道这是否是正确的做法,但它的工作现在。

我用array_map。

  $滑块= array_map(NULL,$幻灯片['形象'],$幻灯片['编辑']);

On the theme im working i'm trying to make slideshow. I have everything set so far i just don't understand how to save them in database when there are multiple slides.

I will skip the code as it's very large ill just add example of input values.

Each slide is made of image upload field(which is basically text field that holds link to image) and textarea field for the text in slide.

So values of the slide are like this.

Slide 1 -> $slide[image][0]  -- $slide[text][0]

Slide 2 -> $slide[image][1]  -- $slide[text][1]

Slide 3 -> $slide[image][2]  -- $slide[text][2]

It's a WordPress theme so wordpress it self is capable to save an array when it recognize it. And if anyone is familiar theme is built upon Options Framework.

When i save this, this is what i get in database.

a:1:{s:13:"slide_example";a:1:{s:5:"image";s:0:"";}}

when (i guess) it should be like this

a:1:{s:13:"slide_example";a:1:{s:5:"image";s:0:"slide text";};a:2:{s:5:"image";s:0:"slide text";};a:3:{s:5:"image";s:0:"slide text";}}

解决方案

I made it working. Im not sure if this is proper approach but it's working for now.

I used array_map.

$slider = array_map(null, $slide['image'], $slide['editor'] );

这篇关于如何保存多个重复字段作为数据库阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆