更新表单问题

时间:2017-11-02 21:52:22

标签: html mysql codeigniter

我有这个表单,在表单上你可以添加输入行,每行都保存为一个组件。我有一个编辑功能,允许您编辑表单现有信息,因此如果您在添加功能中添加了3个组件,则三个组件将显示在编辑功能中。

我遇到的问题是这些行可以在编辑时单独删除,并且表格也应该更新。表campaign_components的作用是因为函数在函数开头删除并在函数末尾插入。表通信没有。

我需要在此添加一个删除查询,但我所做的每一次尝试都会更多地删除它。

MODEL:

public function editCampaign($campaign_id, $data) {

        $this->db->query("UPDATE " . DB_PREFIX . "campaigns SET campaign_name = '" . $this->db->escape($data['campaign_name']) . "', campaign_giving_goal = '" . (float)$data['campaign_giving_goal']
        . "', code = '" . $this->db->escape($data['code']) . "', campaign_active = '" . $this->db->escape($data['campaign_active']) . "', campaign_giving_count_goal = '" . (float)$data['campaign_giving_count_goal'] . "', campaign_owner = '" . $this->db->escape($data['campaign_owner']). "'
        , date_beginning = '" . $this->db->escape($data['date_beginning']). "', date_ending = '" . $this->db->escape($data['date_ending']). "' WHERE campaign_id = '" . (int)$campaign_id . "'");

        $parent_id = 0;

        $this->db->query("DELETE FROM " . DB_PREFIX . "campaign_components WHERE campaign_id = '" . (int)$campaign_id . "'");
        //$this->db->query("DELETE FROM " . DB_PREFIX . "communication WHERE campaign_id = '" . (int)$campaign_id . "'");
        foreach($data['component_module'] as $component_data) {

            if ($component_data['component_type'] =='EVENT'){

            if(isset($component_data['component_parent_id'])){
                $parent_id = $component_data['component_parent_id'];

                $this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($component_data['component_type']) . "', date_starting = '" . $this->db->escape($component_data['component_start_date']). "', date_ending = '" . $this->db->escape($data['date_ending']). "', date_added = NOW() WHERE product_id = '" . (int)$parent_id . "'");
                $this->db->query("UPDATE " . DB_PREFIX . "product_description SET name = '" . $this->db->escape($component_data['component_name']) . "', language_id = '1' WHERE product_id ='" . (int)$parent_id . "'");
            }else{

                $this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($component_data['component_type']) . "', date_starting = '" . $this->db->escape($data['date_beginning']). "', date_ending = '" . $this->db->escape($data['date_ending']). "', date_added = NOW()");
                $parent_id = $this->db->getLastID();


                $this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET name = '" . $this->db->escape($component_data['component_name']) . "', language_id = '1', product_id ='" . (int)$parent_id . "'");
                $this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET category_id = '82', product_id ='" . (int)$parent_id . "' ");

            }

        }else{

            if(isset($component_data['component_parent_id'])){
                $parent_id = $component_data['component_parent_id'];
      //  $this->db->query("DELETE FROM " . DB_PREFIX . "communication WHERE communication_id = '" . (int)$parent_id . "'");
                $this->db->query("UPDATE " . DB_PREFIX . "communication SET subject = '" . $this->db->escape($component_data['component_name']) . "', channel = '" . $this->db->escape($component_data['component_type']) . "', status = '" . $this->db->escape($component_data['component_status']) . "'
                , status_date = '" . $this->db->escape($component_data['component_start_date']). "', status = '" . $this->db->escape($component_data['component_status']) . "', created_by = '" . $this->db->escape($component_data['component_owner']) . "', date_added = NOW(), campaign_id = '" . (int)$campaign_id . "' WHERE communication_id = '" . (int)$parent_id . "'");
        }else{
                $this->db->query("INSERT INTO " . DB_PREFIX . "communication SET subject = '" . $this->db->escape($component_data['component_name']) . "', channel = '" . $this->db->escape($component_data['component_type']) . "', status = '" . $this->db->escape($component_data['component_status']) . "'
                , status_date = '" . $this->db->escape($component_data['component_start_date']). "', created_by = '" . $this->db->escape($component_data['component_owner']) . "', date_added = NOW(), campaign_id = '" . (int)$campaign_id . "'");

                $parent_id = $this->db->getLastID();
            }
        }

        $this->db->query("INSERT INTO " . DB_PREFIX . "campaign_components SET component_type = '" . $this->db->escape($component_data['component_type']) . "', component_status = '" . $this->db->escape($component_data['component_status']) . "'
        , component_owner = '" . $this->db->escape($component_data['component_owner']). "', campaign_id = '" . (int)$campaign_id . "', parent_id = '" . (int)$parent_id . "'");
    }

        $this->cache->delete('parent_id');

        return $campaign_id;
    }

控制器:

public function edit() {
        $this->load->language('campaigns/campaign');

        $this->document->setTitle($this->language->get('heading_title'));

        $this->load->model('campaigns/campaign');
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
            $campaign_id = $this->request->get['campaign_id'];

            $this->model_campaigns_campaign->editCampaign($campaign_id, $this->request->post);

            $this->session->data['success'] = $this->language->get('text_success');

            $this->response->redirect($this->url->link('campaigns/campaign', 'token=' . $this->session->data['token'] . $url, true));
        }

        $this->getForm();
    }

enter image description here

0 个答案:

没有答案