1

cree una tabla en php que me entregará todos los registros de km de una patente que esta almacenados en una BD mysql, la idea es que me entregue todos los registros de una patente en particular pero me entrega varias tablas y solo quiero que aparezca una con los registros, o con los últimos 10 registros, pero solo en una tabla.

Esto es lo que intente.

<form method="post">
      <center>
        <h4>Recorrido Km</h4>
   <label for="" >Ingrese Patente en Mayúscula y sin guion:
   </label>
 </center>
 <center>
   <br>
   <input type="text" name="Patente" placeholder="Patente">
   <input type="submit" value="buscar" name="buscar">
 </center>
</form>

<?php
   if(isset($_POST['buscar']))
   {
  include("conexion.php");
      $Patente = $_POST['Patente'];
  $consu="SELECT Patente, Fecha_Reg, Km
FROM Km
WHERE Patente='$Patente'";
  $resultado = mysqli_query($conexion,$consu);
   while($consu = mysqli_fetch_array($resultado))
{

echo "<br>";
  echo
  "
  <table width=\"60%\" border=\"1\">
    <tr>
   <td><b><center>Patente</center></b></td>
   <td><b><center>Fecha_Reg</center></b></td>
   <td><b><center>Km</center></b></td>
    </tr>
    <tr>
    <td>".$consu['Patente']."</td>
    <td>".$consu['Fecha_Reg']."</td>
    <td>".$consu['Km']."</td>
    </tr>
</table>
";

}
}
?>

1 respuesta 1

0

Tienes que sacar la cabecera y el final de la tabla del bucle, y dejar dentro solo las filas que se van generando dinámicamente.

Es decir, esto:

while($consu = mysqli_fetch_array($resultado))
{

echo "<br>";
  echo
  "
  <table width=\"60%\" border=\"1\">
    <tr>
   <td><b><center>Patente</center></b></td>
   <td><b><center>Fecha_Reg</center></b></td>
   <td><b><center>Km</center></b></td>
    </tr>
    <tr>
    <td>".$consu['Patente']."</td>
    <td>".$consu['Fecha_Reg']."</td>
    <td>".$consu['Km']."</td>
    </tr>
</table>
";

}

lo cambias por esto:

echo "
<br>
<table width=\"60%\" border=\"1\">
  <tr>
    <td><b><center>Patente</center></b></td>
    <td><b><center>Fecha_Reg</center></b></td>
    <td><b><center>Km</center></b></td>
  </tr>
";
while($consu = mysqli_fetch_array($resultado))
{
  echo
  "
  <tr>
    <td>".$consu['Patente']."</td>
    <td>".$consu['Fecha_Reg']."</td>
    <td>".$consu['Km']."</td>
  </tr>
";
}
echo "</table>";

Prueba y nos cuentas.

1
  • 1
    muchas gracias, si me ha funcionado. el 30 nov. 2022 a las 13:23

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.