2017-04-06 3 views
0

を供給: enter image description here無効な引数は、私のプログラムは私が何をすべきかわからない、正常に動作していないCodeIgniterの

はこれを見てください: enter image description here

S

私は、このエラーメッセージが表示されましたここ

は私のコードです: 私のコントローラファイル(ホーム):

<?php 

    class Home extends CI_Controller{ 

     public function __construct(){ 
      parent::__construct(); 

      $this->load->model("Crudmodel"); 

     } 


public function index(){ 

    # get all data in Study table 
    $selectStudys = $this->Crudmodel->selectStudys(); 


    foreach ($selectStudys as $key => $study) 
    { 
     # get UserNames 
     $user = $this->Crudmodel->getName($study['user_id']); 

     #get Subject Names 
     $subject = $this->Crudmodel->getSubName($study['subject_id']); 


     #append both NEW VALUES to same array 

     if(!empty($user[0]['username'])){ 
     $data[$key]['user_id'] = $user[0]['username']; 
     // your main problem can be this. may be it is not getting value from query this is why we have put validation on model function and error handler condition here 
     }else{ 
     $data[$key]['user_id'] = ''; // or anything as your else condition you can use as error handler 
     } 
     if(!empty($subject[0]['name'])){ 
     $data[$key]['subject_id'] = $subject[0]['name']; 
     // your main problem can be this. may be it is not getting value from query this is why we have put validation on model function and error handler condition here 
     }else{ 
      $data[$key]["subject_id"] = ""; 
      // or anything you can use as error handler 
     } 

    } 


    $data['records'] = $selectStudys; 
    $this->load->view('home', $data); 

} 

} 
?> 

Crudmodel:

 class Crudmodel extends CI_Model{ 

     public function __construct(){ 
     parent::__construct(); 

     $this->load->database(); 

     } 


     function selectStudys() 
{ 
    $query= $this->db->query("SELECT * FROM cursadas"); 
    if($query->num_rows()>0){ 
     $result = $query->result_array(); 
    }else{ 
     $result = ""; 
      // or anything you can use as error handler 
     return $result; 
    } 
} 

function getName($name) 
{ 
    $query= $this->db->query("SELECT username FROM usuarios WHERE id = $name "); 
    if($query->num_rows()>0){ 
    $result = $query->result_array(); 
    }else{ 
    $result = ""; 
      // or anything you can use as error handler 
    return $result; 
    } 
} 

いけない、今何をすべきか知っている:(

は、あなたが私を助けることを願っ:S

+0

「$ selectStudys」が配列かどうかを確認してください。 –

+0

あなたはこれまでに何を試しましたか? –

+0

@Purushottamzendeを意味する print_r($ selectStudys)? –

答えて

0

問題がモデルです。あなたはelseの中に何かを返すだけです。簡単な修正、returnを移動します。

行がない場合は、おそらく空の配列を返す必要があります。それで、foreachは、それが空であっても、何かを扱うことができます。 foreachは、ループ内で使用できないもの、例えば文字列が与えられた場合には突然停止します。

function selectStudys() 
{ 
    $query= $this->db->query("SELECT * FROM cursadas"); 
    if($query->num_rows()>0){ 
     $result = $query->result_array(); 
    }else{ 
     $result = array(); 
    } 
    return $result; 
} 
+0

メイトigotこのエラーを: https://i.gyazo.com/e4d927cd2801208c06c587c12d630de9.png コードエラーライン:たぶん https://i.gyazo.com/baf4ceb5f6f9959cecbb670f01e9dc62.png –

+0

あなたは '$ selectStudys = $を変更したため – DFriend

+0

EDIT:プログラムはテーブルを表示しますが、何もフェッチしません:( https:// i(); $ this => CruiseModel-> selectStudys .gyazo.com/6fbe430aa613c5504db78cc9f59a9395.png –

関連する問題