大家好我在模型中给出了如下功能
$query = $this->db->get();
$result = $query->result();
$data[] = $result;
但遇到错误时遇到错误
严重性:注意
消息:未定义的变量:数据
文件名:models / 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;
}
答案 0 :(得分: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;
}
答案 1 :(得分:2)
您必须先定义$data
。
$data = array();
更改
$data[] = $result;
要
$data = $result;
答案 2 :(得分:1)
在将任何内容放入$ data之前,请将其定义为空数组,如下所示:
$data = array();
答案 3 :(得分:1)
您的$data
变量未定义。
它附加了$result
以下是更新的代码:
$data = array();
$query = $this->db->get();
$result = $query->result();
$data[] = $result;