title: error message in php in codeigniter, Undefined variable: data
body: <p>hi all in model i gave in function as follows</p>
  
  <pre><code>$query = $this-&gt;db-&gt;get();
              $result = $query-&gt;result();
              $data[] = $result;
  </code></pre>
  
  <p>but am getting error as   A PHP Error was encountered</p>
  
  <p>Severity: Notice</p>
  
  <p>Message:  Undefined variable: data</p>
  
  <p>Filename: models/survey_model.php</p>
  
  <p>Line Number: 845</p>
  
  <p>null</p>
  
  <p>what was the for this. can someone help me please</p>
  
  <pre><code>function get_actual_details_model($fin_year,$state){
          $this-&gt;db-&gt;select('*');
          $this-&gt;db-&gt;from('survey_respondent_info');
          $this-&gt;db-&gt;where('state', $state);
          $queryYr = $this-&gt;db-&gt;get();
          $resYr = $queryYr-&gt;result();
          foreach ($resYr as  $surveyId) {
              $this-&gt;db-&gt;select('budgets.*, budget_funding.*, marketing_budget.*, personnel_budget.*, grants_budget.*');
              $this-&gt;db-&gt;from('budgets');
              $this-&gt;db-&gt;join('budget_funding', 'budget_funding.budget_id = budgets.budget_id', 'left');
              $this-&gt;db-&gt;join('marketing_budget', 'marketing_budget.budget_id = budgets.budget_id', 'left');
              $this-&gt;db-&gt;join('personnel_budget', 'personnel_budget.budget_id = budgets.budget_id', 'left');
              $this-&gt;db-&gt;join('grants_budget', 'grants_budget.budget_id = budgets.budget_id', 'left');
              $this-&gt;db-&gt;where('budgets.financial_year',$fin_year);
              $this-&gt;db-&gt;where('budget_option_id', 1);
              $this-&gt;db-&gt;where('survey_id', $surveyId-&gt;survey_id);
            $data = array();
  $query = $this-&gt;db-&gt;get();
  $result = $query-&gt;result();
  $data[] = $result;
          }
          return $data;
        }
  </code></pre>