Código PHP:
<?php
session_start();
?>
<html>
<head>
<style type="text/css">
#primero {
text-align:center;
font-family:Castellar;
font-size:16px;
font-weight:bold;
}
#segundo {
clear:both;
}
div.centraTabla{
text-align: center;
}
div.centraTabla table {
margin: 0 auto;
text-align: left;
}
#centrar {
width:100%;
border:4px solid black;
<!--margin:0 auto;-->
}
#noMostrar {
text-align:center;
}
</style>
<link rel="stylesheet" type="text/css" media="print" href="noMostrar.css" />
</head>
<body>
<div id="primero">
<div id="escudo">
<img src="IMG-20150611-WA0016.jpg" width="106" height="161" /><br /><br />
GASTOS
</div>
</div>
<div class="centraTabla" id="tabla" >
<?php
$conexion = mysqli_connect("localhost","root","","adma");
$consulta = mysqli_query($conexion,"select * from gastos");
$total = mysqli_query($conexion,"select sum(total) as total from gastos");
$nfilas = mysqli_num_rows($consulta);
$numeroFilas = mysqli_num_rows($consulta);
if ($nfilas > 0) {
?>
<div id="segundo">
<?php
echo "<table id='centrar' border='solid' align='center' width='80%' border='1' cellspacing='0' cellpadding='0' valign='middle' style='border-collapse':collapse'>";
echo "<tr><td width='100'> <center><b>Referencia</b></center> </td><td width='100'><center><b>Fecha</b></center></td><td> <center><b>Concepto </b></center></td><td width='50'><center><b> Cantidad </b></center> </td><td width='100'><center><b> Precio</b></center> </td><td width='100'> <center><b>Total</b></center></td></tr>";
for ($i=0;$i<$nfilas;$i++){
echo "<tr>";
$fila=mysqli_fetch_array($consulta);
echo "<td>" , $fila["referencia"] , "</td><td>" , $fila["fecha"] , "</td><td>" , $fila["concepto"] , "</td><td>" , $fila["cantidad"] , "</td><td>" , $fila["precio"] , "E", "</td><td>",$fila["total"],"E","</td>";
echo "<br />";
}
echo "</table>";
if ($numeroFilas > 0){
echo "<br />";
$fila=mysqli_fetch_array($total);
echo "<b>TOTAL </b>";
echo $fila["total"];
echo "E";
}
?>
<br /><br /><br />
</div>
</div>
<div id="noMostrar">
<form action="consultarFechaGastos.php" method="post">
<fieldset>
<legend><B>CONSULTAR POR FECHA</B></legend><br />
De
<input type="date" name="deIngresos" />
Hasta
<input type="date" name="hastaIngresos"><br /><br />
<input type="submit" value="Consultar por fecha">
</fieldset>
</form>
<form action="menu.php">
<input type="submit" value="Volver al menu">
</form>
</div>
</body>
</html>
<?php
}
?>