dongti7838 2013-02-17 09:58
浏览 110
已采纳

在Codeigniter中查询结果为空

I have piece of PHP code written in Codeigniter framework that returns nothing (an empty set). Have a look at it and tell me what is wrong with it.

function sbsn($serial){
    $this->db->select('asset_types.name as type_name,asset_brands.name as brand_name');
    $this->db->from('asset_types,asset_brands,assets');
    $this->db->where('assets.type_code','asset_types.code');
    $this->db->where('assets.brand_code','asset_brands.code');
    $this->db->where('serial_no',$serial); 
    $result = $this->db->get();
    return $result;
}
  • 写回答

3条回答 默认 最新

  • dpdp42233 2013-02-18 07:03
    关注

    The problem can be easily solved by joining the tables in the following way.

    $this->db->select('at.name as type_name,ab.name as brand_name');
    $this->db->from('asset_types as at,asset_brands as ab');
    $this->db->join('assets as a', 'a.type_code = at.code and a.brand_code as ab.code');
    $this->db->where('a.serial_no',$serial); 
    $result = $this->db->get()->result_array();
    return $result;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波