PHP - Chekbox para filtrar resultados de buscador

 
Vista:
Imágen de perfil de Ale
Val: 83
Ha disminuido su posición en 8 puestos en PHP (en relación al último mes)
Gráfica de PHP

Chekbox para filtrar resultados de buscador

Publicado por Ale (54 intervenciones) el 02/11/2017 19:03:33
Buenas, tengo un buscador en un listado que busca en cualquier campo en la bd y muestra el resultado de la busqueda en la misma tabla. Funciona de 10, el tema es que quiero implementarle un chekbox para que NO muestre los datos del campo GENERO que diga MULTIPLE...dejo lo que tengo funcionando a ver si alguien me puede ayudar en implementarlo, gracias de antemano y disculpen todo el código, esta bastante sucio y con basura innecesaria...

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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<body background="fondo/fondo.png" style="background-attachment: fixed" width="100%" height="100%">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!DOCTYPE>
<header>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<section class="wrapper">
		<nav>
			<ul>
				<li><a href="../index.php">Hall Of Fame</a></li>
				<li><a href="../cartuchos/index.php">Cartuchos</a></li>
				<li><a href="index.php">Consolas</a></li>
				<li><a href="../familyonline/index.php">Jugar!</a></li>
			</ul>
	    </nav>
    </section>
</header>
 
 
 
<body>
 
<?php
require 'conexion.php';
$where = "";
if(!empty($_POST))
{
$valor = $_POST['campo'];
if(!empty($valor)){
$where = "WHERE codigo LIKE '%$valor%' or nombre LIKE '%$valor%'  or detalle LIKE '%$valor%' or genero LIKE '%$valor%'  or comentario LIKE '%$valor%'";
}
}
$sql = "SELECT * FROM consolas $where  order by nombre asc";
$resultado = $mysqli->query($sql);
$contador = 0;
?>
 
 
</head>
 
 
<html lang="es">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.css" rel="stylesheet">
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.js"></script>
<script type="text/javascript">
 
	$(function() {
		$("table").tablesorter({debug: true})
		$("a.append").click(appendData);
	});
	</script>
</head>
<body>
<div class="container">
<div class="row">
 
<h2 style="visibility: hiddenxxx; text-align:center" >Catálogo de consolas</h2>
<hr>
</div>
<div class="row">
<table1 border="0" width="100%">
	<tr>
		<td><form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
        <b>Buscar</b><br>
		<input type="text" id="campo" name="campo" autocomplete="off"/>
        <input type="submit" id="enviar" name="enviar" value="Aceptar" class="btn btn-info" />
		<img src="gif/transparente.png" width="45%" height="1">
 
		<td align="right"><a href="index.php" class="btn btn-primary">Actualizar (F5)</a>
		<a href="nuevo.php" class="btn btn-primary">Nuevo Registro</a><a class="btn btn-default" href="optimizar.php" target="_blank" onclick="window.open(this.href,this.target,'width=400,height=100,top=100,left=100,toolbar=no,location=no,status=no,menubar=no');return false;"> <span class="glyphicon glyphicon-wrench"></span> &nbsp; Optimizar BD!</a></td>
	</tr>
	 </form>
	 </td>
</table>
 
</div>
<br>
<!--<div class="row table-responsive">-->
<table id="mi-tabla" id="tablesorter" class="table table-striped table table-bordered table-condensed">
<thead>
 
<tr>
<th width="35"><center>#</center></th>
<th width="50"><center>ID</center></th>
<th width="80"><center>Código</center></th>
<th width="190"><center>Nombre</center></th>
<th width="150"><center>Género</center></th>
<th width="111"><center>Imágenes</center></th>
<th width="290"><center>Detalle</center></th>
<th width="157"><center>Comentario</center></th>
<!--<th><center>Stock</center></th>-->
 
<th><center>Editar</center></th>
 
</tr>
</thead>
<tbody>
<?php while($row = $resultado->fetch_array(MYSQLI_ASSOC)) {
$color = array(
    '1' => '<td width="1%" bgcolor="#00FF00">',
    '0' => '<td width="1%" bgcolor="#d90000">'
);
$contador++;?>
<tr>
<td width="35" height="100"><center><?php  echo $contador ; ?></td>
<td width="50" height="100"><center><?php echo $row['id']; ?></td>
<td width="80" height="100"><center><?php echo $row['codigo']; ?></td>
<td width="190" height="100"><?php echo $row['nombre']; ?></td>
<td width="150" height="100"><center><?php echo $row['genero']; ?></td>
 
<td width="110" height="80">
	<?php
	$id = $row['id'];
	$path = "files/".$id;
	if(file_exists($path)){
		$directorio = opendir($path);
		while ($archivo = readdir($directorio))
		{
			if (!is_dir($archivo)){
				echo "<div data='".$path."/".$archivo."'><a href='".$path."/".$archivo."' title='Ver Archivo Adjunto'><span class=''></span></a>";
				echo " <img class='zoom' src='files/$id/$archivo' width='100' />";
			}
		}
	}
	?>
</td>
 
<td width="290" ><div class=scrolbar><font size=2><?php echo $row['detalle']; ?></font></div></td>
<td width="157"height="100"><?php echo $row['comentario']; ?></td>
<!--php echo $color[$row['stock']]; echo $row['stock']; ?>-->
 
 
 
<td height="100"><center><a href="modificar.php?id=<?php echo $row['id']; ?>"><span class="glyphicon glyphicon-pencil" ></span></a>
<a href="#" data-href="eliminar.php?id=<?php echo $row['id']; ?>" data-toggle="modal" data-target="#confirm-delete"><span class="glyphicon glyphicon-trash"></span></a></td>
</center></tr>
<?php } ?>
</tbody>
</table>
<!--</div>-->
 
<!-- Modal -->
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Eliminar Registro</h4>
</div>
<div class="modal-body">
¿Desea eliminar este registro?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a class="btn btn-danger btn-ok">Delete</a>
</div>
</div>
</div>
</div>
<script>
$('#confirm-delete').on('show.bs.modal', function(e) {
$(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
$('.debug-url').html('Delete URL: <strong>' + $(this).find('.btn-ok').attr('href') + '</strong>');
});
</script>
 
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de santi
Val: 588
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Chekbox para filtrar resultados de buscador

Publicado por santi (204 intervenciones) el 03/11/2017 18:21:09
La verdad que no me he leído todo el código pero puedes recibirlo por post de esta forma:

1
2
3
4
5
6
if($_POST['genero'] == NULL)
{
    //si no está marcada la opción en el checkbox
}else{
   //en caso contrario...
}

::)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Ale
Val: 83
Ha disminuido su posición en 8 puestos en PHP (en relación al último mes)
Gráfica de PHP

Chekbox para filtrar resultados de buscador

Publicado por Ale (54 intervenciones) el 06/11/2017 18:27:54
Es que no se cómo agregar ese chekbox, en POST tengo el valor del campo de la búsqueda....

En esta parte conecta

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
require 'conexion.php';
$where = "";
if(!empty($_POST))
{
$valor = $_POST['campo'];
if(!empty($valor)){
$where = "WHERE codigo LIKE '%$valor%' or nombre LIKE '%$valor%'  or detalle LIKE '%$valor%' or genero LIKE '%$valor%'  or comentario LIKE '%$valor%' ";
}
}
$sql = "SELECT * FROM articulos $where order by nombre asc";
$resultado = $mysqli->query($sql);
?>

Y este es el form de busqueda

1
2
3
4
5
6
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
        <b>Buscar entre : </b><br>
	<input type="text" id="campo" name="campo" placeholder="Ingrese valor a buscar..." autocomplete="off"/>
        <input type="submit" id="enviar" name="enviar"  value="Aceptar" class="btn btn-info" />
 
	 </form>

Y así muestra todo en la misma pagina...la verdad que no se qué valor poner en qué parte, sólo se que estos son todos los datos de la búsqueda que usa...quiero que si en genero existe la palabra Múltiple, simplemente no la muestre, pero esto tiene que ser un chekbox que me permita o no buscar esa opcion en la base de datos

Si me pudieras escribir más o menos con lo que tengo ya hecho, te agradecería muchísimo!!! perdón por las molestias...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar