Filter by dates does not show data

1

I have a table with invoice records, I'm filtering by date but it does not show me anything

    <form method="POST">        

        <div id="fechas">
        <label id="lbfecha" for="">Fecha Inicial</label><!--Fecha Inicial-->
        <input id="ipfecha" type="date" name="fecha1" value="<?php echo date("Y-m-d");?>"><!--Fecha Inicial-->
        <label id="lbfecha" for="">Fecha Final</label><!--Fecha Final-->
        <input id="ipfecha" type="date"  name="fecha2" value="<?php echo date("Y-m-d");?>"><!--Fecha Final-->
        <input type="submit" name="Filtrar" value="Filtrar">
        </div>


<!--=====================================
=            TABLA                =
======================================-->
    <div id="tablapedidodet"> <!--estilo de la tabla css/pedidodet.css-->   
        <br/>
        <table align="center"> <!-- inicia tabla-->
            <thead>
                <tr> <!-- inicia encabezado de la tabla-->
                    <!--<th>checkbox</th>  columnas de la tabla-->
                    <th>id</th> <!-- columnas de la tabla-->
                    <th>XML</th> <!-- columnas de la tabla-->
                    <th>PDF</th> <!-- columnas de la tabla-->
                    <th>FECHA</th> <!-- columnas de la tabla-->
                    <th>UDN</th> <!-- columnas de la tabla-->
                </tr> <!-- termina encabezado de la tabla-->
            </thead>

    <?php 

            $f1=isset($_POST['$fecha1']);
            $f2=isset($_POST['$fecha2']);

            $sqlfechas = "SELECT
                                fac_codigo_k,
                                fac_xml,
                                fac_pdf,
                                DATE_FORMAT(fac_fecha, '%d/%m/%Y') AS fac_fecha,
                                sysudn_codigo_k
                            FROM
                                facturas
                            WHERE
                                fac_fecha 
                            BETWEEN 
                                STR_TO_DATE('$f1','%d/%m/%Y') 
                            AND 
                                STR_TO_DATE('$f2','%d/%m/%Y')";
            if (isset($_POST['Filtrar'])) {
            $res = mysqli_query($conexion,$sqlfechas);
            while ($mostrar = mysqli_fetch_array($res)) { //muestra resultados
    ?> 
            <tr>
                <td><link rel="stylesheet" type="text/css"><?php echo $mostrar['fac_codigo_k']?></td> <!-- muestra codigo de registro-->
                <td><a href="<?php echo $mostrar["fac_xml"];?>" download="<?php echo $mostrar["fac_xml"];?>"><?php echo $mostrar['fac_xml']?></a></td> 
                <td><a href="<?php echo $mostrar["fac_pdf"];?>" download="<?php echo $mostrar["fac_pdf"];?>"><?php echo $mostrar['fac_pdf']?></a></td>
                <td><?php echo $mostrar['fac_fecha']?></td> <!-- muestra registro de pdf-->
                <td><?php echo $mostrar['sysudn_codigo_k']?></td> <!-- muestra udn-->
            </tr>

            <?php
                }} //termina de mostrar resultado 
            ?>

            </thead>
        </table> <!-- termina tabla-->
    </div>
<!--====  End of TABLA  ====-->
    </form>
    
asked by Jesus Alejandro Sanchez Doming 02.10.2018 в 19:32
source

1 answer

1

Did you test the query in phpMyAdmin to verify that it actually returns results? What about $ _ POST ['Filter'] ? Is any value sent by Post? Maybe he does not enter because of that condition. If you verified all that, try in the query modify:

WHERE fac_fecha 

for

WHERE DATE_FORMAT(fac_fecha, '%d/%m/%Y')

Greetings

    
answered by 02.10.2018 в 19:39