I have a form that adds the total amount of all the installments. I put a conditional where it tells me if the array has data print me the total otherwise I print a message.
I do not know what my error is, but it does not print the message. I continue to print the array with value but obvious emptied.
Here's the code I have:
reports.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Reportes</title>
<?php include 'inc/head_comun.php'; ?>
</head>
<body>
<?php include 'inc/menu.php'; ?>
<div class="container" >
<br>
<div class="panel panel-success">
<div class="panel-heading" align="center"><h3>REPORTES</h3></div>
<div class="panel-body">
<form class="form-inline" align="center" method="POST" action="reportes.php">
<div class="form-group">
<label for="nombre" >Fecha inicial: </label>
<input class="form-control " id="nombre" type="date" name="fecha_in" value="<?php echo date("Y-m-d");?>"/>
</div>
<div class="form-group">
<label for="email">Fecha final: </label>
<input class="form-control" id="email" type="date" name="fecha_fin" value="<?php echo date("Y-m-d");?>"/>
</div>
<button type="submit" class="btn btn-success" name="buscar">Buscar</button>
</form>
<br>
<?php
require_once "modelo/Conectar.php";
$con=Conectar::conexion();
if (isset($_POST["buscar"])) {
$fecha_inicio=$_POST["fecha_in"];
$fecha_final=$_POST["fecha_fin"];
$sql=$con->prepare("SELECT TRUNCATE(SUM(cantidad),3) as total from abono Where fecha BETWEEN :fecha_in AND :fecha_fin");
$sql->execute(array(':fecha_in'=>$fecha_inicio, ':fecha_fin'=>$fecha_final));
$filas=$sql->fetchAll();
if (count($filas)>0){
echo "hay".var_dump($filas);
}else{
echo "esta vacia ".var_dump($filas);
}
/* if (count($filas)>0) {
foreach ($filas as $registros){
?>
<div class="form-group form-inline" align="center" style="border-image: initial; border: 1px solid green;">
<h3>Total cobro entre fechas:
<span class="label label-warning"> <?php echo $registros["total"];?> $
</span></h3>
</div>
<?php
}
}else{
este es el mensaje que no me imprime cuando no hay abonos con las fechas ingresadas
echo "No hay abonos en las fechas indicadas";
}*/
}
?>
<?php include 'inc/piePagina.php' ?>
<?php include 'inc/footer_comun.php'; ?>
</body>
</html>
The result of the conditional when it is greater than zero of var_dump
is: array(1) { [0]=> array(2) { ["total"]=> string(6) "90.000" [0]=> string(6) "90.000" } } hay
Otherwise the result you print is: array(1) { [0]=> array(2) { ["total"]=> NULL [0]=> NULL } } hay