我的模型中有以下代码。
这是我的原始代码。我已经测试过我的 $category_id 的值 = 1
function getSubCategory($category_id){
$this->db->select('id, subcategory');
$this->db->from('subcategory');
$this->db->where('category_id', $category_id);
$this->db->order_by("subcategory", "asc");
$query = $this->db->get();
return $query->result();
}
但是我遇到了$this-db->where不起作用的问题。
function getSubCategory($category_id){
$cat = 1;
$this->db->select('id, subcategory');
$this->db->from('subcategory');
$this->db->where('category_id', $cat);
$this->db->order_by("subcategory", "asc");
$query = $this->db->get();
return $query->result();
}
我尝试了这行代码只是为了确保我没有做任何语法错误。有了这行代码,我得到了我想要的东西。我想知道是什么让我的原始代码不起作用。
如果有人能帮忙,那将是一个很大的帮助。谢谢。
事实证明,我遇到的问题来自我调用的 AJAX 函数,以调用模型中的方法。
答案在这里看到
AJAX 不显示结果