<?php
	$servername = "localhost";
    $username = "cre12591_rematesduran";
  	$password = "pia1970pia1970";
  	$dbname = "cre12591_crj58049_globalre_login";

	$conn = new mysqli($servername, $username, $password, $dbname);
      if($conn->connect_error){
        die("Conexión fallida: ".$conn->connect_error);
      }

    $salida = "";

    $query = "SELECT * FROM auto WHERE modelo NOT LIKE '' ORDER By lote LIMIT 1000";

    if (isset($_POST['consulta'])) {
    	$q = $conn->real_escape_string($_POST['consulta']);
    	$query = "SELECT * FROM auto WHERE patente LIKE '%$q%' OR modelo LIKE '%$q%' OR marca  LIKE '%$q%' OR ano  LIKE '%$q%' OR patente LIKE '$q' ";
    }

    $resultado = $conn->query($query);

    if ($resultado->num_rows>0) {
    	$salida.="<table class='table table-striped'>
    			<thead class='bg-warning'>
    				<tr id='titulo'>
    					<td>DESCRIPCION</td>
    					<td></td>
    					<td><a href='nuevo_auto.php'> <button type='button' class='btn btn-info'>Nuevo</button> </a></td>
    					<td></td>
    				</tr>

    			</thead>
    			

    	<tbody>";

    	while ($filas = $resultado->fetch_assoc()) {
    		$salida.="<tr>
    					<td>".$filas['patente']."-".$filas['marca']."-".$filas['modelo']."-".$filas['ano']."</td>
    					<td><img src='".$filas['imagen']."' width='100'></td>
    					<td>  <a href='modif_prod1.php?patente=".$filas['patente']."'> <button type='button' class='btn btn-success'>Modificar</button> </a> </td>
    					<td> <a href='eliminar_auto.php?patente=".$filas['patente']."''><button type='button' class='btn btn-danger'>Eliminar</button></a> </td>
    				</tr>";
    				

    	}
    	$salida.="</tbody></table>";
    }else{
        
    	$salida.="<H3> NO SE ENCONTRARON DATOS. </H3> ";
    }


    echo $salida;

    $conn->close();



?>