0
everything jewel?
Recently I took a job to do, and the requester was needing to list some data on a table. I was going to ask all the questions here, but I decided to divide them into parts because it would be easier to understand for me and other people who have the same doubt.
For this case, I’m having problems performing a SELECT with DISTINCT or GROUP BY in Mysql with Codeigniter.
I’m trying to group some dates together to display a single record, and I’m not getting it done.
The result is this image:
Below I leave the code I used.
Model
function get_datas() {
$this->db->order_by($this->id, 'DESC');
$this->db->group_by('data_registro');
$this->db->from($this->tabela);
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result();
} else {
return false;
}
}
Controller:
public function index() {
$data = array(
'show_clientes' => $this->mdl_clientes->get_datas(),
);
$flash_msg = $this->session->flashdata('flash_message');
if (isset($flash_msg) && !empty($flash_msg)) {
$data['flash'] = $flash_msg;
}
$this->load->view('graficos/vwGraficos.php', $data);
}
HTML:
<?php if($show_clientes != FALSE) : ?>
<?php foreach($show_clientes as $clnt) : ?>
<tr>
<td>
<?= $clnt->data_registro; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
I searched several examples on the net, made queries manually, typing all the syntax, but the result is always the same as the image of the table above. Thanks for your help.
Could you inform the structure of the table where you are performing the query and what is the final goal you want to achieve? " Group some dates to display a single record", which would be this single record?
– Vinicius Gabriel
It’s a client table, and there’s the field of that customer’s contact record date. As several customers are registered every day, the ultimate goal is to group the amount of contacts during each day. At first this is it. But right now, what I need is for the dates not to be repeated.
– Jean Carlos