gpt4 book ai didi

php - 使用 codeigniter 在非对象上调用成员函数 num_rows()

转载 作者:行者123 更新时间:2023-11-30 23:11:30 25 4
gpt4 key购买 nike

我被这个愚蠢的问题困住了好几次,我知道我可能犯了一些愚蠢的错误,基本上我有一个 Controller 调用模型函数并返回数据然后将它分配到一个数组中,但是我在非对象成员错误时继续调用成员函数 num_rows,

我的 Controller 函数是:

public function registerNewLease()
{
$this->load->model('AnnualBudget');
$alreadyExist = $this->AnnualBudget->checkAlreadyExist($client_block_ID);
if ($alreadyExist == FALSE)
{
// code if nothing found
} else
{
for ($i=0; $i < $alreadyExist->num_rows(); $i++)
{
$row = $alreadyExist->row($i);
$FY_budget_ID[$i] = $row->FY_budget_ID;
}
}
}

My model is :

public function checkAlreadyExist($client_block_ID)
{
$this->db->select('FY_budget_ID');
$this->db->where('client_block_ID', $client_block_ID);
$query = $this->db->get('fy_budget');
if ($query->num_rows() >= 1)
{
return $query;
} else
{
return FALSE;
}

}

错误在调用num_rows函数的else部分...

最佳答案

试试这个:

public function checkAlreadyExist($client_block_ID)
{
$data = array();
$this->db->select('FY_budget_ID');
$this->db->where('client_block_ID', $client_block_ID);
$data = $this->db->get('fy_budget')->result_array();
return $data;
}

public function registerNewLease()
{
$this->load->model('AnnualBudget');
$FY_budget_ID = array();
$alreadyExist = $this->AnnualBudget->checkAlreadyExist($client_block_ID);
echo $this->db->last_query();
/*if( isset( $alreadyExist ) && count( $alreadyExist ) > 0 ){
foreach ( $alreadyExist as $key => $each )
{
$FY_budget_ID[$key] = $each['FY_budget_ID'];
}
}*/
echo "<pre>";print_r( $alreadyExist );
}

关于php - 使用 codeigniter 在非对象上调用成员函数 num_rows(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19559104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com