【发布时间】:2019-03-14 02:26:35
【问题描述】:
我有一个包含 10 个不同输入字段的表单,它们以任意顺序附加。
获取数据的代码如下:
$news['paragraph'] = $this->input->post('paragraph');
$news['sub_heading'] = $this->input->post('sub_heading');
$news['blurb'] = $this->input->post('blurb');
$news['gallery_image'] = $this->input->post('gallery_image');
$postdescription = $this->input->post('postdescription');
$news['pd_output'] = preg_replace('/(<[^>]+) style=".*?"/i', '$1', $postdescription);
$news['youtube_url'] = $this->input->post('youtube_url');
$news['caption'] = $this->input->post('caption');
$news['facebook'] = $this->input->post('facebook');
$news['twitter'] = $this->input->post('twitter');
$news['instagram'] = $this->input->post('instagram');
$empty_data = array_filter($news);
$keys = array_keys($news_array);
foreach($news_array as $key => $value){
foreach($value as $val){
$data_two = array(
'array_key' => $key,
'content' => $val,
'news_id' => $this->input->post('object_id'),
'created_on' => date("Y-m-d"),
);
$this->db->insert('tbl_news_content',$data_two);
}
}
在 foreach 循环中获取类似的数组
[paragraph] => Array
(
[0] => 1
[1] => 2
)
[sub_heading] => Array
(
[0] => 1
[1] => 2
)
我正在从数组中获取键和值;但我希望在添加表单时输入我的数据。
段落 副标题 图片 段落 段落 图片
我有一张 3 列的表
身份证 键名 内容
Key_name 的值为 Key 内容的价值将是关键的价值
问题是数据被插入为
id key_name 内容 1 段 1 2 第 2 段 3 副标题 1 4 副标题 2
数据没有按照添加表单时提到的顺序插入。
谢谢
【问题讨论】:
-
可以展示一下你的SQL语句吗?
-
或者您能告诉我们您希望 SQL 查询的样子吗?
-
$keys = array_keys($news_array); foreach($news_array as $key => $value){ foreach($value as $val){ $data_two = array( 'array_key' => $key, 'content' => $val, 'news_id' => $this ->input->post('object_id'), 'created_on' => date("Ymd"), ); $this->db->insert('tbl_news_content',$data_two); } }
-
我会更新我的帖子。谢谢
标签: php arrays codeigniter