wunayou 发表于 2012-2-14 20:28:45

产品数量的查询

本帖最后由 wunayou 于 2012-2-15 12:01 编辑

      从品牌得到各种品牌
function get_category()
         {

               $query=$this->db->query(”select * ,(select count(id) from product where id=product_brand.id) as product_count from product_brand“);

               return $query->result();

上面这一语句 能达到从product_brand中建立临时的一列num?

这是控制器         function index()         {               $data['category'] = $this->Mhome->get_category();               $this->load->view('header',$data);               $this->load->view('home');               $this->load->view('footer');                                             }这是视图<? foreach ($category as $row):?><li><?=anchor('home/category/'.$row->id,$row->name) ?>
<?= ($row->product_count?></li><?endforeach;?>
这个产品数量要怎么得到呢?



阿呆 发表于 2012-2-14 21:23:25

你是指返回的产品记录数吗?
count($category)

wunayou 发表于 2012-2-14 22:33:33

阿呆 发表于 2012-2-14 21:23 static/image/common/back.gif
你是指返回的产品记录数吗?
count($category)

是啊$query=$this->db->query("select * from product,product_brand where brand_id=$row->id");
        return $query->num_rows(); 我用这个返回不是数组啊

阿呆 发表于 2012-2-15 10:41:00

$query->result()返回数组
$query->num_rows() 返回记录集
页: [1]
查看完整版本: 产品数量的查询