【问题标题】:Multiple WHERE condition issue at update_batch in CodeIgniterCodeIgniter 中 update_batch 的多个 WHERE 条件问题
【发布时间】:2018-06-07 11:12:56
【问题描述】:

面临在 CodeIgniter 的 update_batch 中使用多个 Where 条件的问题。

没有错误信息没有显示。 以及数据库中的数据没有更新。 但点击 提交按钮 后,由于数据已成功提交,给我 flash message。但数据库无法更新。 请建议我该怎么做!

控制器 ------------------------------------

public function masterPrice_update($m_fran_id = null) 
	{
		$sID   = $this->input->post('m_test_id');
		$sAmt  = $this->input->post('m_updated_test_price');
		$sFranId = $this->input->post('m_fran_id');

		for ($i= 0; $i < count($sID); $i++)
		{
			
			$edited_test[] = array(
				'm_test_id' => $sID[$i],
				'm_updated_test_price' => $sAmt[$i],
				'm_fran_id' => $sFranId[$i]
			);
		}

		if ($this->form_validation->run() === true) {
			$this->franchise_price_model->singlebatch_Test_updt($edited_test);

			$this->session->set_flashdata('message', display('save_successfully'));
			redirect('branch/franchise_price/masterPrice_update');
		}
	}

模态 ---------

public function singlebatch_Test_updt($edited_test =[], $sFranId ='')
{	
	$this->db
	->where('m_fran_id',$sFranId)
	->update_batch($this->fran_test_pricemaster, $edited_test , 'm_test_id' );
}

【问题讨论】:

  • @KalroKokka 先生,您能推荐我吗
  • 您不必在模型方法中使用 where 条件。你可以在这里查看。 :codeigniter.com/user_guide/database/…
  • 请告诉您要更新表格的 id 是什么

标签: php codeigniter multiple-conditions batch-updates


【解决方案1】:

您可以使用 $this->db->last_query() 来打印查询。我认为您在控制器没有将 $sFranId 传递给模型的情况下存在问题。

【讨论】:

  • 我的意思是,$sFranId 它的值不是来自 ControllerModal 吗? @PankajSharma
  • 你没有在控制器中传递值你只传递了一个你正在传递的值 $this->franchise_price_model->singlebatch_Test_updt($edited_test);在模型中,您使用 2 个值函数 singlebatch_Test_updt($edited_test =[], $sFranId ='')
  • 那你能帮我在Controller上写代码吗? @PankajSharma
  • 请尝试将您的控制器线替换为此 $this->franchise_price_model->singlebatch_Test_updt($edited_test,$sFranId);并打印最后一个查询
  • 我已经做了同样的事情,但是没有得到期望值。运行代码时,收到类似的错误消息 -- Unknown column 'Array' in 'where clause'
【解决方案2】:

使用这种类型的查询

$this->db->query("UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition AND condition2");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多