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

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

在 codeigniter 中映射數(shù)據(jù)

在 codeigniter 中映射數(shù)據(jù)

PHP
holdtom 2023-04-02 14:53:06
我有一個(gè)數(shù)據(jù)存儲(chǔ)在數(shù)組中 $roles = [2,4];我想將我在 $roles 中的數(shù)據(jù)與數(shù)據(jù)庫(kù)中的數(shù)據(jù)進(jìn)行映射。如果我像上面那樣在 $roles 中有多個(gè)數(shù)據(jù),我不知道如何映射數(shù)據(jù),而且我不知道如何在表視圖中顯示所有數(shù)據(jù)。我試試這個(gè) if (count($roles) == 1) {  if ($roles[0] == 2) {    $data['need_app'] = $this->Hire_model->need_approval_req($OrganizationID, $requestor_id);  }else if ($roles[0] == 3) {    $data['need_app'] = $this->Hire_model->need_approval_recruiter();  }else if ($roles[0] == 4) {    $data['need_app']=$this->Hire_model->need_approval_hr();  }else if ($roles[0] == 5) {    $data['need_app'] = $this->Hire_model->need_approval_cc($PositionID, $OrganizationID, $requestor_id);  }}else{   for ($i=0; $i < count($roles)-1 ; $i++) {     if ($roles[0] == 2) {      $data['need_app'] = $this->Hire_model->need_approval_req($OrganizationID, $requestor_id);      var_dump(count($data['need_app']));    }else if ($roles[0] == 3) {      $data['need_app'] = $this->Hire_model->need_approval_recruiter();    }else if ($roles[0] == 4) {      $data['need_app']=$this->Hire_model->need_approval_hr();    }else if ($roles[0] == 5) {      $data['need_app'] = $this->Hire_model->need_approval_cc($PositionID, $OrganizationID, $requestor_id);      var_dump(count($data['need_app']));    }    // var_dump(count($data['need_app']));  }}希望有人能幫助我
查看完整描述

2 回答

?
翻翻過去那場(chǎng)雪

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

我寫了一段代碼可以幫助你解決這個(gè)問題,必要時(shí)會(huì)提到注釋。希望對(duì)你有幫助。


foreach ($roles as $role) { 

    if ($role == 2) {

      $data['need_app'][] = $this->Hire_model->need_approval_req($OrganizationID, $requestor_id); // you need to make an array here otherwise the current value will over-write the previous one

      var_dump(count($data['need_app']));

    }else if ($role == 3) {

      $data['need_app'][] = $this->Hire_model->need_approval_recruiter(); // you need to make an array here otherwise the current value will over-write the previous one

    }else if ($role == 4) {

      $data['need_app'][] =$this->Hire_model->need_approval_hr(); // ...

    }else if ($role == 5) {

      $data['need_app'][] = $this->Hire_model->need_approval_cc($PositionID, $OrganizationID, $requestor_id); // ...

    }

    // var_dump($data['need_app']);

}


查看完整回答
反對(duì) 回復(fù) 2023-04-02
?
元芳怎么了

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

 foreach ($roles as $role) {


            if ($role == 2) {


                //your logic here


            } else if ($role == 4) {


                //your logic here


            } else if ($role == WHAT_EVER_YOU_WANTS) {

                //Logic

            }


            //your logic here

        }

所以根據(jù)你的問題


foreach ($roles as $role) {

            if ($role == 2) {

                $data['need_app'] = $this->Hire_model->need_approval_req($OrganizationID, $requestor_id);

            } else if ($role == 3) {

                $data['need_app'] = $this->Hire_model->need_approval_recruiter();

            } else if ($role == 4) {

                $data['need_app'] = $this->Hire_model->need_approval_hr();

            } else if ($role == 5) {

                $data['need_app'] = $this->Hire_model->need_approval_cc($PositionID, $OrganizationID, $requestor_id);

            }

        }

而不是使用類似$role == 4


在函數(shù)內(nèi)創(chuàng)建一個(gè)常量或另一個(gè)變量,并使用該變量值循環(huán)條件。這對(duì)以后的修改很有幫助。


像這樣的東西


$loopValues = [1,2,3,4,5,6] // Or    $loopValues = [['val' => 1, 'function' => functionName()]] <- I prefer this one all the time

然后像下面這樣循環(huán)


 foreach ($roles as $role) {


            if ($role == $loopValues[0]) {


                //your logic here

}

}


查看完整回答
反對(duì) 回復(fù) 2023-04-02
  • 2 回答
  • 0 關(guān)注
  • 174 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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