Good afternoon I'm doing a query on mysql given a date bring me the year and month and the reference for that month, the query is good but it's not bringing me anything, someone to help me find the error.
<?php
//comprobamos que las fechas existan
if(isset($_POST["fecha_desde"])){
$fecha_desde = $_POST["fecha_desde"];
}
if (isset ($_POST["fecha_hasta"])){
$fecha_hasta = $_POST["fecha_hasta"];
$fecha_desde = strtotime($fecha_desde);
$fecha_hasta = strtotime($fecha_hasta);
$fecha_desde = date('Y-m',$fecha_desde);
$fecha_hasta = date('Y-m',$fecha_hasta);
$rs = mysqli_query($mysqli,"SELECT referencia, DATE_FORMAT(fecha_pedido, '%Y%m'), SUM(cantidad), COUNT(referencia) FROM pedidos_detalle INNER JOIN pedidos ON pedidos_detalle.id_pedido = pedidos.id WHERE $_POST[fecha_desde] = DATE_FORMAT(fecha_pedido, '%Y%m') BETWEEN '$fecha_desde' AND '$fecha_hasta' GROUP BY referencia, DATE_FORMAT(fecha_pedido, '%Y%m'), ORDER BY referencia, DATE_FORMAT(fecha_pedido, '%Y%m') ASC");
while ($row = mysqli_fetch_row($rs)){
echo "<option value='$row[0]'>$row[0], $row[1]</option>";
?>