<?php
include('conexion.php');
if(!isset($_POST['Modelo']) || !isset($_POST['Color'])){
return header("location:index.php");
}
$modelo = $_POST['Modelo'];
$Color = $_POST['Color'];
$Descripcion = isset($_POST['Descripcion']);
$num_consultas=mysqli_num_rows(mysqli_query($conexion,"SELECT * FROM tenis WHERE color='".$Color."' OR descripcion='".$modelo."' OR modelo= '".$Descripcion."'"));
if(isset($_GET['pagina'])){
if($_GET['pagina']==1){
$busqueda = "SELECT * FROM tenis WHERE color='".$Color."' OR descripcion='".$modelo."' OR modelo= '".$Descripcion."' LIMIT 0,5";
}else{
$busqueda = "SELECT * FROM tenis WHERE color='".$Color."' OR descripcion='".$modelo."' OR modelo= '".$Descripcion."'LIMIT ".($_GET['pagina']*5).",5";
}
}else{
$busqueda = "SELECT * FROM tenis WHERE color='".$Color."' OR descripcion='".$modelo."' OR modelo= '".$Descripcion."' LIMIT 0,5";
}
$sql_query = mysqli_query($conexion,$busqueda);
?>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body{
background-color: #E8E8E8;
}
table{
margin: auto;
border: none;
width: 70%;
font-family: arial;
}
td{
padding: 30px;
color: #000;
border: none;
text-align: center;
}
h1{
width: 100%;
text-align: center;
margin-bottom: 70px;
}
th{
border: none;
background-color: #FF2b2b;
padding: 10px;
width: 16.6%;
}
</style>
<title></title>
</head>
<body>
<h1>Resultados de busqueda</h1>
<button onclick="window.location='buscar-productos.php'">Regresar</button>
<center style="display: flex;">
<?php
for($a=1; $a<=ceil($num_consultas/5)-1; $a++){
?>
<form action="buscar.php?pagina=<?php echo $a; ?>" method="post" style='width: 100%; margin-bottom: 30px;'>
<input type="text" name="Color" id="color" value="<?php echo $_POST['Color']; ?>" required readonly hidden>
<input type="text" name="Modelo" id="modelo" value="<?php echo $_POST['Modelo']; ?>" required readonly hidden>
<input type='submit' value='<?php echo $a; ?>'>
</form>
<?php
}
if($num_consultas==0){
echo "<strong>NO HAY PRODUCTOS</strong>";
}
?>
</center>
<table border="2px" cellspacing="0" cellpadding="0">
<thead>
<th>ID</th>
<th>Modelo</th>
<th>Precio</th>
<th>Color</th>
<th>Descripcion</th>
<th>Imagen</th>
<th></th>
</thead>
<tbody>
<?php
while($mostrar = mysqli_fetch_array($sql_query)) {
?>
<tr>
<td><?php echo $mostrar['id_tenis']?></td>
<td><?php echo $mostrar['modelo']?></td>
<td><?php echo $mostrar['precio']?></td>
<td><?php echo $mostrar['color']?></td>
<td><?php echo $mostrar['descripcion']?></td>
<td><?php echo "<img src='".$mostrar['imagen']."' width ='60'>"?></td>
<td><?php echo"<a href='comprar-productos/comprar.php'><input type='button' value='Comprar'></a>"?></td>
</tr>
<?php
}
mysqli_close($conexion);
?>
</tbody>
</table>
</body>
</html>