Mysql codeigniter php asc desc order by count result使用php [英] Mysql codeigniter php asc desc order by count result using php

查看:252
本文介绍了Mysql codeigniter php asc desc order by count result使用php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个名为的表:



at_category:


  1. cat_id

  2. 名称

at_categorytaxonomy:


  1. cat_taxonomy_id

  2. cat_id

  3. 分类

at_shop:


  1. shop_id

  2. shop_category

我想通过计算结果来加入这三个表。 p>

例如,在 at_category 表中命名为电子商店的类别,在 at_category_taxonomy 表中,并且此类别ID在 at_shop 表中有两个商店。



例如:aaa,bbb,ccc

  1。 at_category 

______________

cat_id name

1电子商店
2冰淇淋店
_______________

2. at_category_taxonomy

_______________________________________________

cat_taxonomy_id cat_id taxonomy

3 1电子商店
4 2冰淇淋店
_______________________________________________

3. at_shop

________________________________

shop_id shop_name shop_category

1 A 1(即电子商店)
2 B 1(即电子商店)
3 C 1(即电子商店)
4 D 2(即冰淇淋店)

________________________________

现在:类别有3家商店的电子商店和有1家商店的冰淇淋店



期望输出:

  (描述)类别名称(ASC)

3电子商店
1冰淇淋店

当我在商店列中点击asc订单时,输出将是

 否.Of.Shops(ASC)(Desc)类别名称(ASC)

1冰淇淋店
3电子商店
pre>

这是类别名的对应。



现在我想使用codeigniter按照desc命令显示结果。

解决方案

选择电子邮件,计数(*)为c FROM订单GROUP BY电子邮件

  $ this- ; db-> select('COUNT(sh.shop_category)as No_of_shops,cat.name as category_name',FALSE); 
$ this-> db-> from('at_shop sh');
$ this-> db-> join('at_category cat','cat.cat_id = sh.shop_category');
$ this-> db-> order_by('sh.shop_category');
$ query = $ this-> db-> get();
retuen $ query-> result_array();


I have three tables named:

at_category:

  1. cat_id
  2. name

at_category_taxonomy:

  1. cat_taxonomy_id
  2. cat_id
  3. taxonomy

at_shop:

  1. shop_id
  2. shop_category

I want to join those three tables by counting result.

For example the category named as Electronic Shops in at_category table and the value will be stored in at_category_taxonomy table and the this category id's are having two shops in at_shop table. same as for remaining categories aaa, bbb, ccc etc...it may be having one or two shops else zero shops.

Example :

1. at_category

    ______________

    cat_id   name

     1       Electronic Shops
     2       Ice Cream Shops
    _______________

    2. at_category_taxonomy

    _______________________________________________

    cat_taxonomy_id   cat_id   taxonomy

      3                 1       Electronic Shops
      4                 2       Ice Cream Shops
    _______________________________________________

    3. at_shop

    ________________________________

    shop_id   shop_name   shop_category

     1            A         1 (ie.Electronic Shops) 
     2            B         1 (ie.Electronic Shops) 
     3            C         1 (ie.Electronic Shops) 
     4            D         2 (ie.Ice Cream Shops) 

    ________________________________

Now : The category Electronic Shops having 3 shops and Ice cream shops having 1 shop

Expecting output :

No.Of.Shops (ASC) (Desc)    Category Name   (ASC) (Desc)

     3                         Electronic Shops
     1                         Ice cream Shops 

When i click asc order in no.of shops column then the output will be

No.Of.Shops (ASC) (Desc)    Category Name   (ASC) (Desc)

     1                          Ice cream Shops   
     3                          Electronic Shops

This is vise verse for category name too.

now I want to display the result by count the number shops by desc order using codeigniter.

解决方案

select email, count(*) as c FROM orders GROUP BY email

$this->db->select('COUNT(sh.shop_category) as No_of_shops,cat.name as category_name',FALSE);
$this->db->from('at_shop sh');
$this->db->join('at_category cat', 'cat.cat_id = sh.shop_category');
$this->db->order_by('sh.shop_category');
$query = $this->db->get();
retuen $query->result_array();

这篇关于Mysql codeigniter php asc desc order by count result使用php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆