-2

このコードの問題点は何ですか。このエラーの取得

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`)
)
4

2 に答える 2

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();    
    }

通常、これは私には問題なく機能します。試してみて、うまくいくかどうか教えてください..

于 2012-04-11T05:21:11.113 に答える
0

試す

return $query->result_array();
于 2012-04-11T03:30:11.290 に答える