致命错误:调用成员函数结果错误

时间:2012-04-11 02:58:11

标签: php codeigniter

这段代码出了什么问题。得到此错误

Fatal error: Call to a member function result() on a non-object in /system/application/models/miscellaneousmodel.php on line

function getSubCategories($categoryId){
        $this->db->select("CATEGORY_ID,SUB_CATEGORY_URL AS CATEGORY_URL, CATEGORY_DESC,ACTIVE_STATUS,SORT_ORDER");  
        $whereCondition = $array = array('CATEGORY_ID' =>$categoryId);      
        $this->db->where($whereCondition); 
        $query = $this->db->get('TRN_SUB_CATEGORY');                
        return $query->result();    
    }

现在使用以下代码解决了该错误,但

现在没有为SUB_CATEGORY_URL AS CATEGORY_URL显示正确的别名

ResultstdClass Object ( [SUB_CAT_ID] => 1 [CATEGORY_ID] => 1 [CATEGORY_DESC] => EMU Meat [ACTIVE_STATUS] => A [SUB_CATEGORY_URL] => /categories/agriculture-products/emu-meat ) 

$query = $this->db->query("SUB_CATEGORY_ID,SUB_CATEGORY_URL AS CATEGORY_URL, CATEGORY_DESC,ACTIVE_STATUS");
        $whereCondition = $array = array('CATEGORY_ID' =>$categoryId);  
        $this->db->where($whereCondition);  
        $query = $this->db->get("trn_sub_category");
        return $query->result();

这是我的表

CREATE TABLE IF NOT EXISTS `trn_sub_category` (
  `SUB_CAT_ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `CATEGORY_ID` int(10) unsigned NOT NULL,
  `CATEGORY_DESC` varchar(250) NOT NULL,
  `ACTIVE_STATUS` varchar(1) NOT NULL,
  `SUB_CATEGORY_URL` varchar(300) NOT NULL,
  PRIMARY KEY (`SUB_CAT_ID`)
)

2 个答案:

答案 0 :(得分:0)

return $query->result_array();

答案 1 :(得分:0)

让我们试着让你的功能如下:

function getSubCategories($categoryId){
        $select = "CATEGORY_ID,SUB_CATEGORY_URL AS CATEGORY_URL, CATEGORY_DESC,ACTIVE_STATUS,SORT_ORDER";
        $whereCondition = $array = array('CATEGORY_ID' =>$categoryId);
        $this->db->select($select)->where($whereCondition);

        $query = $this->db->get('trn_sub_category');                
        return $query->result();    
    }

通常这对我来说很好,你能试试并告诉我它是否有效......