所有張貼的價值觀我有多種形式,我需要插入幾個值4個用戶,新聞,飼料,LAT(也許6)是由一些ID此相關的表是因爲事件需要所有這些信息。笨的方法來保存在二維數組
我的形式:
<form method="post" action="<?php echo base_url();?>controller/save" name="event"/>
<label>User Name</label>
<!--#####FOR TABLE USER#####-->
<input type="text" name="name">
<input type="text" name="name">
<!--#####FOR TABLE NEWS#####-->
<input type="text" name="title">
<input type="submit" value="body"/>
<!--#######################
OTHER TABLE FIELDS ...
#######################
-->
<input type="submit" value="save"/>
</form>
現在我想傳遞一個二維陣列,以事件模型,然後根據不同的值的插入到對應表
控制器event.php
class Event extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
$this->load->model('event_model');
}
public function save()
{
/** Is it possible to fill this bidimensional array with for loops???? **/
$arr_data = array(
array("person", $this->input->post("name") , $this->input->post("address")),
array("news" , $this->input->post("title") , $this->input->post("body" )),
array("feed" , $this->input->post("id_feed") , $this->input->post("main" )),
array("lat" , $this->input->post("lat1" , $this->input->post("lat" ))
);
$this->event_model->insert_tables($arr_data);
}
}
現在如何接收模型中的數組,並執行插入如何聲明event_model?
class Event_model extends CI_Model {
function Event_model()
{
parent::__construct();
}
function insert_tables($arr_data) {
if("person")
$this->db->insert(person_tb ,
}
}
是否有必要使用implode什麼的,有沒有更好的方式來做到這一點多重插入?
在這個設計的開始我看不到那麼多的意思。你確定你已經看到了替代方案嗎?例如,我認爲使用密鑰會更合乎邏輯。 '陣列(「人」 =>陣列(「名」 => $名字,「地址」 => $地址))' – 2013-03-22 10:01:16