php - 如何在codeigniter中依次更新两个表数据?

标签 php mysql codeigniter sql-update

I create a model to update plan data but now with that i want to update the vendor_plan_task_mapping data because i use the plan data with vendor so when i update the plan after creating a vendor with some plan the updated plan data can't come to vendor task status mapping data hear i create a model for updating plan i have to update task_status_mapp table to be update...

如何使用 vendor_plan_task_status_mapp 表更新计划。

计划更新的模型是

public function updatePlanData(){

    $planId = $this->input->post('plan_id');
    $data = array(

                    'plan_title' => $this->input->post('plan_title'),
                    'plan_price' => $this->input->post('plan_price'),
                    'plan_desc'     => $this->input->post('plan_desc')

                );

    $this->db->where('plan_id', $planId);
    $this->db->update('tbl_plan', $data);


    $this->db->where('plan_id',$planId);
    $this->db->delete('plan_task_mapping');



    foreach ($this->input->post('task_id') as $key => $value)

     {
        $data2 = array(

        'plan_id' => $planId,
        'task_id'   => $value

        );
     // echo "Index {$key}'s value is {$value}.";
           $this->db->insert('plan_task_mapping', $data2);
     }

//-------- HEAR I NEED A CODE TO UPDATE The V_T_S_M table-----------

}

第一次表更新后我想更新 vendr_task_status_mapping 表中的数据?????

最佳答案

在此答案中,如果您更改计划但使用此代码,您必须简单地编辑和更新它 ANGIN 并且此模型为您的任务创建一个新 ID 并再次插入它。

 public function vendorUpdateModel($data)

       {
         $vendor_id = $this->input->post('vendor_id');
         $data = array(
           'category_id' => $this->input->post('category_id'),
           'plan_id' => $this->input->post('plan_id'),
           'city_id' => $this->input->post('city_id'),
           'business_name' => $this->input->post('business_name'),
           'owner_name' => $this->input->post('owner_name'),
           'contact_no1' => $this->input->post('contact_no1'),
           'contact_no2' => $this->input->post('contact_no2'),
           'vendor_email' => $this->input->post('vendor_email'),
           'subscription_date' => $this->input->post('subscription_date'),
           'vendor_description' => $this->input->post('vendor_description'),
           'vendor_address' => $this->input->post('vendor_address')

           );

       $this->db->where('vendor_id', $vendor_id);
       $this->db->update('vendor',$data);

       $this->db->where('vendor_id',$vendor_id);
       $this->db->delete('vendor_task_status_mapping');

       $this->db->select('task_mapp_id');
       $this->db->where('plan_id',$this->input->post('plan_id'));

       $query = $this->db->get('plan_task_mapping');

       foreach($query->result() as $row)

       {
       $data2 = array(

       'task_mapp_id' => $row->task_mapp_id,
       'vendor_id'  => $vendor_id,
          'task_status'  => '0'

          );

             $this->db->insert('vendor_task_status_mapping', $data2);
        }
          return;
         }

关于php - 如何在codeigniter中依次更新两个表数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31717793/

相关文章:

php - mysql 和 php with reSTLer for webservice

javascript - PHP 无法上传图像,也看不到 $image 值。所有其他工作,都是关于ajax,没有刷新表单

php - Codeigniter 根据 View 中的 id 在 View 中显示来自 2 个不同表的数据

php - 页面加载时间超过一分钟 Mysql 和 Codeigniter

php - Magento "File was not uploaded"

php - 无法解决此 SQL 错误

PHP 应用程序 - 快速连接到 HTTPS 服务器

MySQL 5.7 按最新记录分组

php - 模拟保存 propel 对象(不写入表)

jquery - Codeigniter 中的 ERR_EMPTY_RESPONSE