Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/06/2015, 12:05
loloblc
 
Fecha de Ingreso: febrero-2015
Mensajes: 10
Antigüedad: 9 años, 2 meses
Puntos: 0
Div encima de otro

Buenas, como véis el siguiente código muestra un resultado de tabla conforme a la consulta especificada en SQL. El problema es que si la consulta obtiene un resultado, todo funciona perfectamente, pero si obtiene mas de un resultado, la tabla se va desplazando progresivamente hacia abajo en función del numero de registros obtenidos, sin lograr el objetivo, que es la tabla se muestre justo debajo del encabezado. Ruego por favor que alguien me indicara en que estoy fallando. Gracias!!!

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
}
?>