
Combox
Publicado por lean (10 intervenciones) el 25/01/2017 16:25:05
Hola buenas tardes, recién estoy aprendiendo Php y tengo una duda espero me puedan ayudar.
Lo que pretendo es hacer otros combobox para hacer un filtrado mas concreto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?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>
Lo que pretendo es hacer otros combobox para hacer un filtrado mas concreto
Valora esta pregunta


0