Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/02/2011, 18:43
matajazz
 
Fecha de Ingreso: abril-2010
Mensajes: 52
Antigüedad: 14 años, 1 mes
Puntos: 0
Filtro/busqueda php

Hola para todos y gracias de antemano.

Estoy intentando crear un buscador para mi tabla hecha con php/dreamweaver pero de momento no me funciona. Sencillamente no responde, no hace nada.

He echo un form sencillo:

<form action="pagina.php" method="get" name="form1" id="form1">
<input name="busqueda" type="text" id="busqueda" value="<?php echo $_GET['busqueda']; ?>" />
<input name="btnBuscar" type="submit" id="btnBuscar" value="Buscar!" />
</form>

Luego el filtro:

if($_REQUEST["btnBuscar"]!="" && $_REQUEST["busqueda"]!="")
{

if(is_numeric($_REQUEST["busqueda"]))
$filtro="id=". $_REQUEST["busqueda"];
else
$filtro=" provincia like '%".$_REQUEST["busqueda"]."%' or precio like '%".$_REQUEST["busqueda"]."%'";
$mensaje=$filtro;

}else
{
$mensaje="<font color='red'>Escriba Algo</font>";
}

y luego los recordsets y detalles de la tabla

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_cnxaventuras, $cnxaventuras);
$query_rsCategorias = "SELECT * FROM provincia ORDER BY provincia ASC";
$rsCategorias = mysql_query($query_rsCategorias, $cnxaventuras) or die(mysql_error());
$row_rsCategorias = mysql_fetch_assoc($rsCategorias);
$totalRows_rsCategorias = mysql_num_rows($rsCategorias);

mysql_select_db($database_cnxaventuras, $cnxaventuras);
$query_rsProductos = "SELECT * FROM producto ORDER BY precio ASC";
$rsProductos = mysql_query($query_rsProductos, $cnxaventuras) or die(mysql_error());
$row_rsProductos = mysql_fetch_assoc($rsProductos);
$totalRows_rsProductos = mysql_num_rows($rsProductos);

$maxRows_rsProductos = 3;
$pageNum_rsProductos = 0;
if (isset($_GET['pageNum_rsProductos'])) {
$pageNum_rsProductos = $_GET['pageNum_rsProductos'];
}
$startRow_rsProductos = $pageNum_rsProductos * $maxRows_rsProductos;

$colname_rsProductos = "-1";
if (isset($_POST['listaProvincia'])) {
$colname_rsProductos = $_POST['listaProvincia'];
}
mysql_select_db($database_cnxaventuras, $cnxaventuras);
$query_rsProductos = sprintf("SELECT * FROM producto WHERE familia = 'paintball' ORDER BY precio ASC", GetSQLValueString($colname_rsProductos, "text"));
$query_limit_rsProductos = sprintf("%s LIMIT %d, %d", $query_rsProductos, $startRow_rsProductos, $maxRows_rsProductos);
$rsProductos = mysql_query($query_limit_rsProductos, $cnxaventuras) or die(mysql_error());
$row_rsProductos = mysql_fetch_assoc($rsProductos);


if (isset($_GET['totalRows_rsProductos'])) {
$totalRows_rsProductos = $_GET['totalRows_rsProductos'];
} else {
$all_rsProductos = mysql_query($query_rsProductos);
$totalRows_rsProductos = mysql_num_rows($all_rsProductos);
}
$totalPages_rsProductos = ceil($totalRows_rsProductos/$maxRows_rsProductos)-1;

$queryString_rsProductos = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsProductos") == false &&
stristr($param, "totalRows_rsProductos") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsProductos = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsProductos = sprintf("&totalRows_rsProductos=%d%s", $totalRows_rsProductos, $queryString_rsProductos);
?>


Pero no hay manera.
Vuestra ayuda seria impagable.