第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

從單個(gè)表單提交將數(shù)據(jù)插入到多個(gè)表中

從單個(gè)表單提交將數(shù)據(jù)插入到多個(gè)表中

富國滬深 2021-12-02 19:45:26
我有下面提到的表格。并獲得以下輸出。幫助我使用 foreach 循環(huán)獲得如下輸出。array('notification') = array('pos_id' => 'kiran','post_usr' => 'kumar','comment' => 'kaleti');array('project') = array('Project_name' => 'india','Proejct_lang' => 'hyderabad');這是控制器代碼。// controllerpublic function form_submit() {   $total_data = $this->input->post();   print_r($total_data);  //output :Array ( [notification|pos_id] => kiran [notification|post_usr] => kumar [notification|comment] => kaleti [project|Project_name] => india [project|Proejct_lang] => hyderabad )  foreach ( $total_data as $key => $value ) {     $arr = explode("|",$key);     echo $arr[0]."--".$arr[1]."--".$value."<br />";   }}
查看完整描述

1 回答

?
侃侃無極

TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊

這是控制器代碼,您將從中獲取數(shù)據(jù)VIEW作為您將在controller.


// Controller

$data_array1 = array(

    'table_field_name_here' => $this->input->post('pos_id'),

    'table_field_name_here' => $this->input->post('post_usr'),

    'table_field_name_here' => $this->input->post('comment'),

);


$data_array2 = array(

    'table_field_name_here' => $this->input->post('Project_name'),

    'table_field_name_here' => $this->input->post('Proejct_lang'),

);  


$table_1 = 'table_name';

$table_2 = 'table_name';

$record_id_1 = $this->Common_model->insert_into_table($table_1, $data_array1);

$record_id_2 = $this->Common_model->insert_into_table($table_2, $data_array2);

if($record_id_1 && $record_id_2){

    // success ...!

}else{

    // fail ...!    

}

model您將從控制器調(diào)用的函數(shù)。


// Model

function insert_into_table($table, $data) {

    // echo "<pre>asdf";print_r($data);exit;

    $insert = $this->db->insert($table, $data);

    $insert_id = $this->db->insert_id();

    if ($insert) {

        return $insert_id;

    } else {

        return false;

    }

}

希望您能了解使用模型將數(shù)據(jù)插入到兩個(gè)表中是多么簡單。


查看完整回答
反對(duì) 回復(fù) 2021-12-02
  • 1 回答
  • 0 關(guān)注
  • 362 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)