Ver Mensaje Individual
  #7 (permalink)  
Antiguo 04/01/2012, 03:30
bloguero
 
Fecha de Ingreso: noviembre-2011
Mensajes: 97
Antigüedad: 12 años, 5 meses
Puntos: 3
Respuesta: Validacion en una busqueda

Si lo abrevie un poco, pero mira aqui te muestro un poco mejor haber q opinas:

este de mi pagina principlal
mini.html

<form name="buscador" method="get" action="resultados.php">
<input type="text" name="s" onkeypress="return validar(event)" />
<a href="javascript:void(0)" title="Buscar" onClick="document.buscador.submit();">
<img src="ima/lupa.png" width="24" height="24" border="0">
</a>
</form>


y este es mi archivo resultados.php



<?php
require_once("conexion/conexion.php");


/*este primer select es con el fin de luego hacer una paginacion, solo quite la parte de html y php que muestra esto de la paginacion(esto iba al final)*/
$sql="select count(*) as cuantos from producto
where
prodnomb like '%".$_GET["s"]."%'
or
stokact like '%".$_GET["s"]."%'
or
precio like '%".$_GET["s"]."%'
";


$res=mysql_query($sql,$con);
if ($reg=mysql_fetch_array($res))
{
$total=$reg["cuantos"];
}
$resto=$total % 5;
$ultimo=$total-$resto;

//************************************************** **************
if (isset($_GET["pos"]))
{
$inicio=$_GET["pos"];
}
else

{
$inicio=0;
}

/*AQUI COMIENZA MI PROBLEMA, ESTO ES LO QUE AGREGUE, YA LO HE REVISADO Y NADA, CUANDO CLIKEO EN BUSCAR, ME MANDA A "RESULTADOS.PHP" PERO CON LA PAGINA VACIOA*/
if(isset($_GET["s"]))
{
if($_GET["s"]=='')
{
echo no hay nada;//aqui pones como quieras indicar que la busqueda no ha insertado nada
}
else{

//ejecuta la consulta de busqueda
$sql="select * from producto
where
prodnomb like '%".$_GET["s"]."%'
or
stokact like '%".$_GET["s"]."%'
or
precio like '%".$_GET["s"]."%'
";

}
}
$res=mysql_query($sql,$con);

?>

<html>
<head>
<title>Buscador</title>
<style type="text/css">
#principal{ width:800px; height:100%}
#header{ width:800px; height:100px; float:left; background-color:#666666; color:#FFFFFF}
#menu{ width:800px; height:25px; float:left}
.boton{ width:100px; height:25px; float:left; background-color:#FF0000; color:#FFFFFF}
.buscador{ width:300px; height:25px; float:left}
#main{ width:800px; height:100%; float:left}

</style>
</head>


<body>

<div id="principal">

<div id="menu">



<!--acá va el div menu-->
<div align="center" class="buscador">
<form name="buscador" method="get" action="resultados.php">
<input type="text" name="s">
<a href="javascript:void(0)" title="Buscar" onClick="document.buscador.submit();">
<img src="ima/lupa.png" width="24" height="24" border="0">
</a>
</form>
</div>
<!--acá va el div menu-->

</div>

<div align="center" id="main">
<table align="center" width="400">
<tr>
<td valign="top" align="center" width="400" colspan="3">
<h3>Resultados de su b&uacute;squeda</h3>
</td>
</tr>

<tr style="background-color:#666666; color:#FFFFFF; font-weight:bold">
<td valign="top" align="center" width="200">
Producto
</td>
<td valign="top" align="center" width="100">
Cantidad
</td>
<td valign="top" align="center" width="100">
Precio
</td>
</tr>
<?php
if (mysql_num_rows($res)==0)

{
?>
<tr>
<td valign="top" align="center" width="400" colspan="3" style="background-color:#f0f0f0">
No hay registros para ese criterio de b&uacute;squeda
</td>
</tr>
<?php
}else
{

$impresos=0;
while ($reg=mysql_fetch_array($res))
{
$impresos++;
?>
<tr style="background-color:#f0f0f0">
<td valign="top" align="center" width="200">
<?php echo chao_tilde(str_replace("".$_GET["s"]."","<b>".$_GET["s"]."</b>",$reg["prodnomb"]));?>
</td>
<td valign="top" align="center" width="100">
<?php echo chao_tilde(str_replace("".$_GET["s"]."","<b>".$_GET["s"]."</b>",$reg["stokact"]));?>
</td>
<td valign="top" align="center" width="100">
<?php echo chao_tilde(str_replace("".$_GET["s"]."","<b>".$_GET["s"]."</b>",$reg["precio"]));?>
</td>
</tr>
<?php
}
}
?>
<tr>
<td valign="top" align="center" width="500" colspan="3">
<hr>

</td>
</tr>

</table>
</div>

</div>

</body>
</html>



Ahi les paso mi codigo, espero su ayuda, gracias