首页 > 解决方案 > 如何在不同的codeigniter中显示归档

问题描述

大家好,我想区分字段product_code,我想显示所有字段表事务:

---------------------------------------------------
| id | product_code | price | datetime            |
---------------------------------------------------
| 1  | 001          |20     | 2018-18-12 09:09:09 |
| 2  | 002          |30     | 2018-18-12 08:09:09 |
| 3  | 001          |20     | 2018-18-12 08:08:08 |
---------------------------------------------------

这是我的模型:

$this->db->distinct('product_code');
$this->db->select('id','product_code','price','datetime');
$this->db->from($this->table);
return $this->db->get()->result_array();

标签: distinctcodeigniter-3

解决方案


您可以为您的问题尝试此解决方案:

$this->db->distinct();
$this->db->select('id','product_code','price','datetime');
$this->db->from($this->table);
return $this->db->get()->result_array();

echo $query->num_rows();

或者

$this->db->select('DISTINCT(product_code), ');  
$this->db->from($this->table);  
$query=$this->db->get();  

print_r($this->db->get()->result_array());

echo $query->num_rows();exit;

我希望它会帮助你。


推荐阅读