Lo que pretendo es hacer otros combobox para hacer un filtrado mas concreto.
En este caso quiero listar el valores de "carrera" y "id_alumno", lo que pretendo es poder tener mas filtros para una besuqueada mas exacta.
Código: Seleccionar todo
<?php
 
////////////////// CONEXION A LA BASE DE DATOS ////////////////////////////////////
 
$host="localhost";
$usuario="root";
$contraseña="root";
$base="itic";
 
$conexion= new mysqli($host, $usuario, $contraseña, $base);
if ($conexion -> connect_errno)
{
	die("Fallo la conexion:(".$conexion -> mysqli_connect_errno().")".$conexion-> mysqli_connect_error());
}
////////////////// VARIABLES DE CONSULTA////////////////////////////////////
 
$where="";
$nombre=$_POST['xnombre'];
$carrera=$_POST['xcarrera'];
 
 
////////////////////// BOTON BUSCAR //////////////////////////////////////
 
if (isset($_POST['buscar']))
{
 
 
 
	if (empty($_POST['xcarrera']))
	{
		$where="where nombre like '".$nombre."%'";
	}
 
	else if (empty($_POST['xnombre']))
	{
		$where="where carrera='".$carrera."'";
	}
 
	else
	{
		$where="where nombre like '".$nombre."%' and carrera='".$carrera."'";
	}
}
/////////////////////// CONSULTA A LA BASE DE DATOS ////////////////////////
 
$alumnos="SELECT * FROM alumnos $where ";
$resAlumnos=$conexion->query($alumnos);
$resCarreras=$conexion->query($alumnos);
 
if(mysqli_num_rows($resAlumnos)==0)
{
	$mensaje="<h1>No hay registros que coincidan con su criterio de búsqueda.</h1>";
}
?>
<html lang="es">
 
	<head>
		<title>Filtro de Búsqueda PHP</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
 
		<link href="css/estilos.css" rel="stylesheet">
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
 
	</head>
	<body>
		<header>
			<div class="alert alert-info">
			<h2>Filtro de Búsqueda PHP</h2>
			</div>
		</header>
		<section>
			<form method="post">
				<input type="text" placeholder="Nombre..." name="xnombre"/>
 
				<select name="xcarrera">
					<option value="">Carrera </option>
					<?php
						while ($registroCarreras = $resCarreras->fetch_array(MYSQLI_BOTH))
						{
							echo '<option value="'.$registroCarreras['carrera'].'">'.$registroCarreras['carrera'].'</option>';
						}
 
					?>
 
 
				</select>
 
 
 
				<button name="buscar" type="submit">Buscar</button>
			</form>
			<table class="table">
				<tr>
					<th>ID_Alumno</th>
					<th>Nombre</th>
					<th>Carrera</th>
					<th>Grupo</th>
				</tr>
 
				<?php
 
				while ($registroAlumnos = $resAlumnos->fetch_array(MYSQLI_BOTH))
				{
 
					echo'<tr>
						 <td>'.$registroAlumnos['id_alumno'].'</td>
						 <td>'.$registroAlumnos['nombre'].'</td>
						 <td>'.$registroAlumnos['carrera'].'</td>
						 <td>'.$registroAlumnos['grupo'].'</td>
						 </tr>';
				}
				?>
			</table>
 
			<?php
				echo $mensaje;
			?>
		</section>
	</body>
</html>
