用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1983|回复: 3
收起左侧

[已解决] 二个查询怎么相结合

[复制链接]
发表于 2012-2-20 22:47:35 | 显示全部楼层 |阅读模式
本帖最后由 wunayou 于 2012-2-21 13:35 编辑

function get_product($id)
         {
                 $query=$this->db->query("select * from product where brand=(select name from product_brand where id=$id)");
         
         
                 return $query->result();
                 
         }

function get_product($id)         {                 $query=$this->db->query("select * from product where brand=(select name from product_brand where id=$id)");                                   return $query->num_rows()                          }
这二个怎么结合起来啊

发表于 2012-2-21 09:40:12 | 显示全部楼层
你的结合是神马意思?
PHP复制代码
 
/*我的理解*/
/*result*/
        public function getProductByOption($id ='',$option='data')
        {
                $query = $this->db
                                ->query(
                                                "select * from `product`
                                                 where brand=(select name from product_brand where id={$id})"
);
 
                if ( $option != 'data')
                {
                        return $this->query->num_rows();
                }
                return $this->query->result();
 
        }
 
复制代码
 楼主| 发表于 2012-2-21 11:51:16 | 显示全部楼层
大道达人 发表于 2012-2-21 09:40
你的结合是神马意思?

不是了啊 我就是想把二个方法查询的结果 用一个方法把他查询出来
发表于 2012-2-21 13:11:25 | 显示全部楼层
wunayou 发表于 2012-2-21 11:51
不是了啊 我就是想把二个方法查询的结果 用一个方法把他查询出来
PHP复制代码
 
$rstCode['num'] = $this->query->num_rows();
$rstCode['data'] = $this->query->result();
 
复制代码

本版积分规则