codeigniter - codeigniter:试图获取非对象的属性
问题描述
严重性:通知消息:尝试获取非对象的属性文件名:admin/search_result.php 行号:73
我正在尝试从费用表中的费用列中检索数据。我不知道代码有什么问题。
<?php
$term_fee = $this->db->get_where('fees' , array(
'student_id' => $row['student_code'], 'term' => $running_term,
'year' => $running_year ))->row()->fees;
echo $term_fee;
?>
这是我的看法。需要帮忙
解决方案
该错误意味着您的查询失败。你不应该假设它会成功。这样做的方法是在使用任何生成查询结果的函数之前检查调用的结果。
我最好的猜测是您提供的值之一不可用。因此,请仔细检查您的输入值。确保它们在那里并且是你所期望的。
尽管此代码可能无法修复结果,但至少您捕获了失败的查询,并且将获得有关已完成操作的更有意义的信息。
<?php
$query = $this->db->get_where('fees', array(
'student_id' => $row['student_code'],
'term' => $running_term,
'year' => $running_year )
);
if(isset($query))
{
$term_fee = $query->row()->fees;
echo $term_fee;
}
else
{
//do something about the failed query
echo "Query Failed. Here's what you asked the database to do:<br>";
echo $this->db->last_query();
}
当“get family”函数失败时会发生什么,它返回 FALSE 并且 FALSE 不是具有任何属性的“对象”。它当然没有row()
附加功能。因此,在使用任何查询结果函数之前,请务必检查什么get()
或get_where()
返回。
推荐阅读
- shiny - 具有默认选定值的 ShinyTree
- python - 如何为图像/图标小部件设置动画
- javascript - 使用 jQuery 和 PHP 使用从 MySQL 数据库查询的 JSON 数据填充 HTML 选择字段
- javascript - 在春季上传多个文件,每个文件都有附加信息
- sql - 如何在 oracle 中拆分用逗号分隔的名称(偶数出现)?
- google-cloud-platform - gsutil rsync 是否会为 Google Cloud Storage Coldline 存储分区产生额外费用
- python - 阈值必须是数字且非NAN,打印numpy数组时,为什么numpy.nan在python3中未定义
- vb.net - 如何在 vb.net 的文本文件中输入附加数据?
- .net-core - .NET Core API 无法连接到 MS LocalDB
- django - Django从另一个表中的模型输出1个字段