Reporte.php
<form action="Filtro.php" method="POST">
<fieldset>
<p> <center>
<label for="username">FILTRAR POR:</label>
</p>
<p>
<label for="username">Nombre</label>
<input id="nombre" type="text" name="nombre" size="18" value="<?php if (isset($_SESSION["usuario"])){echo $_SESSION["usuario"];}?>"/>
</p>
<p>
<label for="passwd">Apellido</label>
<input id="apellido" type="text" name="apellido" size="18" value="<?php if (isset($_SESSION["clave"])){echo $_SESSION["clave"];}?>"/>
</p>
<p>
<label for="correo">Direccion</label>
<input id="direccion" type="text" name="direccion" size="18" value="<?php if (isset($_SESSION["direccion"])){echo $_SESSION["direccion"];}?>"/>
</p>
<p>
<label for="correo">Telefono</label>
<input id="telefono" type="text" name="telefono" size="18" value="<?php if (isset($_SESSION["telefono"])){echo $_SESSION["telefono"];}?>"/>
<p>
<input type="radio" name="b3" value="1" class="imputradio" checked /><label for="username">ASENDENTE</label>
<br>
<input type="radio" name="b3" value="2" class="imputradio"/><label for="username">DESENDENTE</label>
</p>
<p>
<input type="submit" name="b2" class="button" value="FILTRAR" /> <input type="submit" name="b1" class="button" value="LISTAR TODO" /></center>
</p>
</fieldset>
</form>
</body>
</html>
<fieldset>
<p> <center>
<label for="username">FILTRAR POR:</label>
</p>
<p>
<label for="username">Nombre</label>
<input id="nombre" type="text" name="nombre" size="18" value="<?php if (isset($_SESSION["usuario"])){echo $_SESSION["usuario"];}?>"/>
</p>
<p>
<label for="passwd">Apellido</label>
<input id="apellido" type="text" name="apellido" size="18" value="<?php if (isset($_SESSION["clave"])){echo $_SESSION["clave"];}?>"/>
</p>
<p>
<label for="correo">Direccion</label>
<input id="direccion" type="text" name="direccion" size="18" value="<?php if (isset($_SESSION["direccion"])){echo $_SESSION["direccion"];}?>"/>
</p>
<p>
<label for="correo">Telefono</label>
<input id="telefono" type="text" name="telefono" size="18" value="<?php if (isset($_SESSION["telefono"])){echo $_SESSION["telefono"];}?>"/>
<p>
<input type="radio" name="b3" value="1" class="imputradio" checked /><label for="username">ASENDENTE</label>
<br>
<input type="radio" name="b3" value="2" class="imputradio"/><label for="username">DESENDENTE</label>
</p>
<p>
<input type="submit" name="b2" class="button" value="FILTRAR" /> <input type="submit" name="b1" class="button" value="LISTAR TODO" /></center>
</p>
</fieldset>
</form>
</body>
</html>
Filtrar.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
session_start();
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
{
die ('No se establecio la conexion'.mysql_error());
}
else
{
mysql_select_db("bddagenda",$conexion);
$order="asc";
if (isset($_POST['b3'])){
if ($_POST['b3']=="2")
$order="desc";
}
if (isset($_POST['b2'])){
$value=$_POST['nombre'].$_POST['apellido'].$_POST['direccion'].$_POST['telefono'];
$sql=mysql_query("select * from agenda where concat(Nombre,Apellido,Direccion,telefono) like concat('%','$value','%') order by Nombre $order");
}
if (isset($_POST['b1'])){
$sql=mysql_query("select * from agenda order by Nombre $order");
}
echo "<center><table border='1'><tr><td>ID</td><td>NOMBRE</td><td>APELLIDO</td><td>EDAD</td><td>TELEFONO</td><td>DIRECCIÓN</td></tr>";
while($fila=mysql_fetch_array($sql))
{
echo "<tr>";
echo "<td>".$fila['idagenda'],''."</td>";
echo "<td>".$fila['Nombre'],''."</td>";
echo "<td>".$fila['Apellido'],''."</td>";
echo "<td>".$fila['edad'],''."</td>";
echo "<td>".$fila['telefono'],''."</td>";
echo "<td>".$fila['Direccion'],''."</td>";
echo "</tr>";
}
echo "</table></center";
echo "<br><br><br>";
}
?>
<form action="Reporte.php" method="POST">
<center><input type="submit" name="Submit" class="button" value="REGRESAR" /></center>
</form>
</body>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
session_start();
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
{
die ('No se establecio la conexion'.mysql_error());
}
else
{
mysql_select_db("bddagenda",$conexion);
$order="asc";
if (isset($_POST['b3'])){
if ($_POST['b3']=="2")
$order="desc";
}
if (isset($_POST['b2'])){
$value=$_POST['nombre'].$_POST['apellido'].$_POST['direccion'].$_POST['telefono'];
$sql=mysql_query("select * from agenda where concat(Nombre,Apellido,Direccion,telefono) like concat('%','$value','%') order by Nombre $order");
}
if (isset($_POST['b1'])){
$sql=mysql_query("select * from agenda order by Nombre $order");
}
echo "<center><table border='1'><tr><td>ID</td><td>NOMBRE</td><td>APELLIDO</td><td>EDAD</td><td>TELEFONO</td><td>DIRECCIÓN</td></tr>";
while($fila=mysql_fetch_array($sql))
{
echo "<tr>";
echo "<td>".$fila['idagenda'],''."</td>";
echo "<td>".$fila['Nombre'],''."</td>";
echo "<td>".$fila['Apellido'],''."</td>";
echo "<td>".$fila['edad'],''."</td>";
echo "<td>".$fila['telefono'],''."</td>";
echo "<td>".$fila['Direccion'],''."</td>";
echo "</tr>";
}
echo "</table></center";
echo "<br><br><br>";
}
?>
<form action="Reporte.php" method="POST">
<center><input type="submit" name="Submit" class="button" value="REGRESAR" /></center>
</form>
</body>
EJECUCION
Al ejecutar con el servidor localhost nos aparece esta ventana .
Donde seleccionamos el orden si es asendente o desendente y al selecciona LISTAR TODO nos muestra todos los siguientes registros en el orden que deseamos.Aqui esta en orden asendente.Aqui en orden desendente y el boton REGRESAR nos lleva a la primera pagina.
Si deseamos buscar por los siguiente campos que tiene este formulario solo llenamos el campo que deseamos y seleccionamos FILTRAR.
Ejemplo por Nombre.
Nos muestra solo los que tengan el nombre Marla.Por ejemplo por Direccion.
Nos muestra solo los que tienes como direccion Quito.
No hay comentarios:
Publicar un comentario