2013-08-23 47 views
-1

大家好模型,我給在功能如下錯誤消息:數據

$query = $this->db->get(); 
      $result = $query->result(); 
      $data[] = $result; 

但作爲一個PHP錯誤遇到

嚴重性我得到的錯誤:請注意

消息:未定義變量:數據

文件名:型號/ survey_model.php

行號:845

什麼是這一點。有人可以幫我請

function get_actual_details_model($fin_year,$state){ 
     $this->db->select('*'); 
     $this->db->from('survey_respondent_info'); 
     $this->db->where('state', $state); 
     $queryYr = $this->db->get(); 
     $resYr = $queryYr->result(); 
     foreach ($resYr as $surveyId) { 
      $this->db->select('budgets.*, budget_funding.*, marketing_budget.*, personnel_budget.*, grants_budget.*'); 
      $this->db->from('budgets'); 
      $this->db->join('budget_funding', 'budget_funding.budget_id = budgets.budget_id', 'left'); 
      $this->db->join('marketing_budget', 'marketing_budget.budget_id = budgets.budget_id', 'left'); 
      $this->db->join('personnel_budget', 'personnel_budget.budget_id = budgets.budget_id', 'left'); 
      $this->db->join('grants_budget', 'grants_budget.budget_id = budgets.budget_id', 'left'); 
      $this->db->where('budgets.financial_year',$fin_year); 
      $this->db->where('budget_option_id', 1); 
      $this->db->where('survey_id', $surveyId->survey_id); 
      $data = array(); 
$query = $this->db->get(); 
$result = $query->result(); 
$data[] = $result; 
     } 
     return $data; 
     } 
+4

你在哪裏設置$的數據? – Anigel

+0

[PHP:「Notice:Undefined variable」和「Notice:Undefined index」]的可能重複(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) –

回答

2

你應該使用的代碼的例子。 這只是一個例子!

$data = array(); 
$query = $this->db->get('table'); 
$result = $query->result(); 
$data[] = $result; 

return $data; 

你很少更新代碼

function get_actual_details_model($fin_year,$state){ 
    $data = array(); // Data need to be in start 
    $this->db->select('*'); 
    $this->db->from('survey_respondent_info'); 
    $this->db->where('state', $state); 
    $queryYr = $this->db->get(); 
    $resYr = $queryYr->result(); 
    foreach ($resYr as $surveyId) { 
     $this->db->select('budgets.*, budget_funding.*, marketing_budget.*, personnel_budget.*, grants_budget.*'); 
     $this->db->from('budgets'); 
     $this->db->join('budget_funding', 'budget_funding.budget_id = budgets.budget_id', 'left'); 
     $this->db->join('marketing_budget', 'marketing_budget.budget_id = budgets.budget_id', 'left'); 
     $this->db->join('personnel_budget', 'personnel_budget.budget_id = budgets.budget_id', 'left'); 
     $this->db->join('grants_budget', 'grants_budget.budget_id = budgets.budget_id', 'left'); 
     $this->db->where('budgets.financial_year',$fin_year); 
     $this->db->where('budget_option_id', 1); 
     $this->db->where('survey_id', $surveyId->survey_id); 
     $query = $this->db->get(); 
     $result = $query->result(); 
     $data[] = $result; 
    } 
    return $data; 
} 
+0

它不工作相同的錯誤越來越 – user2412936

+0

顯示你的所有模型,因爲,如果它是相同的錯誤,那麼問題就不存在了。 – Arturs

+0

函數get_actual_details_model($ fin_year,$ state){ \t $ this-> db-> select('*'); \t \t $ this-> db-> from('survey_respondent_info'); \t \t $ this-> db-> where('state',$ state); \t \t $ queryYr = $ this-> db-> get(); \t \t $ resYr = $ queryYr-> result(); – user2412936

1

之前,你把任何東西在$數據,把它定義爲空數組是這樣的:沒有定義

$data = array(); 
1

$data變量。 而且它附有$result

以下是更新後的代碼:

$data = array(); 
$query = $this->db->get(); 
$result = $query->result(); 
$data[] = $result; 
2

你必須定義你$data第一。

$data = array(); 

變化

$data[] = $result; 

$data = $result;