php - 如何使用 Jquery 拆分两个数组并传递给 ajax?
问题描述
插入数据库时出现错误。
它的显示列ARRAY。如何解决?而不是我想传递所有日期(在屏幕截图中仅显示日期列中的日期)
我想在代码中知道我做错了什么。为什么数组会这样来?
PHP 模式
$data_jobschedule = array(
'jobschedule_id' => $jobschedule_id,
'Activity_area_id' => $Activity_area_id,
'Contract_id' => $this->input->post('getcontract_id'),
'job_freq_id' => $this->input->post('getcontractbranch_freq'),
'job_schedule_dates' => $this->input->post('getschedule'),
//'job_schedule_frequency' => $this->input->post('getjob_schedule_frequency'),
'created_at' =>$created_Dt
);
$insert_id = 0;
if ($this->db->insert("activity_area", $data)) { //AM INSERTING ANOTHER RECORD ALSO TO DIFFERENT TABLE
$this->db->insert('job_schedule', $data_jobschedule); //HERE IS THE TABLE I NEED TO ADD DATES AND FREQUENCY
$insert_id = $this->db->insert_id();
}
解决方案
所以你的帖子数据是一个数组,你需要遍历它。在你的 php 模型上,尝试改变这个
$data_jobschedule = array(
'jobschedule_id' => $jobschedule_id,
'Activity_area_id' => $Activity_area_id,
'Contract_id' => $this->input->post('getcontract_id'),
'job_freq_id' => $this->input->post('getcontractbranch_freq'),
'job_schedule_dates' => $this->input->post('getschedule'),
//'job_schedule_frequency' => $this->input->post('getjob_schedule_frequency'),
'created_at' =>$created_Dt
);
$insert_id = 0;
if ($this->db->insert("activity_area", $data)) { //AM INSERTING ANOTHER RECORD ALSO TO DIFFERENT TABLE
$this->db->insert('job_schedule', $data_jobschedule); //HERE IS THE TABLE I NEED TO ADD DATES AND FREQUENCY
$insert_id = $this->db->insert_id();
}
至
$insert_id = 0;
if ($this->db->insert("activity_area", $data)) { //AM INSERTING ANOTHER RECORD ALSO TO DIFFERENT TABLE
if (is_array($this->input->post('getschedule'))) {
foreach($this->input->post('getschedule') as $value) {
$this->db->insert('job_schedule', array(
'jobschedule_id' => $jobschedule_id,
'Activity_area_id' => $Activity_area_id,
'Contract_id' => $this->input->post('getcontract_id'),
'job_freq_id' => $this->input->post('getcontractbranch_freq'),
'job_schedule_dates' => $value[0], //assume array form like your screenshot
'job_schedule_frequency' => $value[1],
'created_at' =>$created_Dt
));
}
$insert_id = $this->db->insert_id();
}
}
推荐阅读
- terraform - 从 terraform 中的嵌套地图程序性地生成单项地图
- html - 设置 src={{form.image_url}} 无法呈现图像,但 form.image_url 确实包含 URL (Django)
- go - 我应该使用 Get 方法来获取值还是应该直接使用字段?
- php - 使用 PHP 打印 Json 结果
- php - Xdebug:无法连接到调试客户端(Phpstorm + WSL2)
- excel - 使用Excel VBA加载IE11不兼容的网站
- django - 如何使某些字段只能由 Django 中的某些类型的用户访问?
- c# - 在等待 GetAsync 的结果时定期做一些事情
- c - 当我要标记超过 10 个字符时,我正在制作的词法分析器中出现损坏的最大尺寸错误
- python - 当值的长度与索引的长度不匹配时如何填充 nan?