简体   繁体   English

使用Codeingiter选择具有相同值的行

[英]select rows with the same value using Codeingiter

How to select all with the same value using codeigniter. 如何使用codeigniter选择具有相同值的所有对象。

    +-------+-------------+------------+
    | id    | coupon_code | Barcode    |
    +-------+-------------+------------+
    | 1     | COUPON02    | 12542      |   
    | 2     | COUPON02    | 11229      | 
    | 3     | COUPON03    | 11823      | 
    | 4     | COUPON03    | 47875      | 
    +-------+-----------+--------------+

   public  function fetch_available_coupon(){

    $coupon_code = $this->uri->segment(3);

    $this->db->select('*');
    $this->db->from('barcode');
    $this->db->where('coupon_code', $coupon_code);
    $query = $this->db->get();

    if ($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
            $data[] = $row;
        }
        return   $data;
    }else{
        return false;        
    }
 }

in my result it only show 1 row not the not all the same Coupon_Code 在我的结果中,它仅显示1行,而不是全部相同的Coupon_Code

Im using codeigniter as my active record. 我正在使用codeigniter作为我的活动记录。 Please Help thank you 请帮忙谢谢

use where condition instead of group by 使用where条件而不是分组依据

 $this->db->where('coupon_code', $coupon_code); 

You can use GROUP BY to group values from a column, and, if you wish, perform calculations on that column. 您可以使用GROUP BY对列中的值进行分组,并且,如果需要,可以对该列执行计算。 You can use COUNT, SUM, AVG, etc., functions on the grouped column. 您可以在分组列上使用COUNT,SUM,AVG等功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM