Return value grouped by date

0

I have a table in MySQL , which stores the confirmations of my clients in my website, having as fields: id | cod_cliente | data , being the date the main.

What I need is to group and return the result of the day.

Example:

  

Das 05/10/2017 | 80 confirmations
  Das 06/06/2017 | 100 confirmations

<?php

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT COUNT(*) AS 'DATA' FROM 'confirmacao' WHERE 'ID_CLI' = 27001";
$result = $conn->query($sql);

$sql2 = "SELECT * FROM 'confirmacao' WHERE 'ID_CLI' = 27002 GROUP BY 'DATA' ORDER BY 'ID' DESC";
$result2 = $conn->query($sql2);

while($row2 = $result2->fetch_assoc()) {
    echo $row2["DATA"];
    echo "<br />";
}

while($row = $result->fetch_assoc()) {
    echo $row["DATA"];
    echo "<br />";
}

?>

But it does not return correctly. how to do this? Thank you.

    
asked by anonymous 06.10.2017 / 23:59

1 answer

0
<?php

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT DATE_FORMAT(data, "%d/%m/%Y"), COUNT(*) FROM confirmacao WHERE cod_cliente = 27001 GROUP BY data ORDER BY id DESC";
$result = $conn->query($sql);


while($row2 = $result2->fetch_assoc()) {
    echo $row2["DATA"];
    echo "<br />";
}

while($row = $result->fetch_assoc()) {
    echo $row["DATA"];
    echo "<br />";
}

?>
    
07.10.2017 / 04:23