Buscador php y mysql

Hola te cuento estoy desarrollando una página para una inmobiliaria el problema que tengo con el buscador yo desarrolle la página en dreamweaver y tengo un localhost allí tengo la base de datos.
En el index tengo un formulario html que tiene la opciones ciudad, zona, tipo, arriendo o venta. Las primeras son menu/lista y las otras de opción.
En la hoja de resultados creo un juego de recgistros y ahí esta el probme no se como relacionar mi html con la hoja php de resultados.
Las búsquedas no me funcionan.
No se si me puedas guiar he leído tutoriales pero estoy muy comfundida.
Gracias
Un abrazo

1 Respuesta

Respuesta
1
Básicamente en el formulario de tu HTML en el ACTION del FORM debes de poner la página destino PHP...
Sin más datos no te puedo ayudar mucho más!
El script donde esta el formulario de búsqueda
<?php require_once('Connections/centrica.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $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_centrica, $centrica);
$query_busqueda = "SELECT * FROM propiedades";
$busqueda = mysql_query($query_busqueda, $centrica) or die(mysql_error());
$row_busqueda = mysql_fetch_assoc($busqueda);
$totalRows_busqueda = mysql_num_rows($busqueda);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Documento sin título</title>
</head>
<body>
<form action="resultado.php" method="post" name="busqueda" id="busqueda">
  <label for="buscarciudad"></label>
<table width="360" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1"><label for="buscarzona"></label></td>
<td width="211"><label for="buscarciudad2"></label>
        <select name="buscarciudad" id="buscarciudad2">
          <option value="bogota" <?php if (!(strcmp("bogota", $row_busqueda['ciudad']))) {echo "selected=\"selected\"";} ?>>Bogota</option>
          <option value="santa marta" <?php if (!(strcmp("santa marta", $row_busqueda['ciudad']))) {echo "selected=\"selected\"";} ?>>Santa MArta</option>
      </select>
        <select name="buscarzona" id="buscarzona">
          <option value="noroccidente" <?php if (!(strcmp("noroccidente", $row_busqueda['zona']))) {echo "selected=\"selected\"";} ?>>Noroccidente</option>
      </select>
      <input type="submit" name="buscar" id="buscar" value="Enviar"></td>
<td width="10"> </td>
<td width="1"><label for="buscar"></label></td>
<td width="22"> </td>
</tr>
</table>
</form>
</body>
</html>
<?php
mysql_free_result($busqueda);
?>
scrip donde esta el resultado
<?php require_once('Connections/centrica.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $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;
}
}
$maxRows_resultado = 10;
$pageNum_resultado = 0;
if (isset($_GET['pageNum_resultado'])) {
  $pageNum_resultado = $_GET['pageNum_resultado'];
}
$startRow_resultado = $pageNum_resultado * $maxRows_resultado;
mysql_select_db($database_centrica, $centrica);
$query_resultado = "SELECT * FROM propiedades WHERE propiedades.ciudad AND propiedades.zona  ORDER BY propiedades.ciudad, propiedades.zona";
$query_limit_resultado = sprintf("%s LIMIT %d, %d", $query_resultado, $startRow_resultado, $maxRows_resultado);
$resultado = mysql_query($query_limit_resultado, $centrica) or die(mysql_error());
$row_resultado = mysql_fetch_assoc($resultado);
if (isset($_GET['totalRows_resultado'])) {
  $totalRows_resultado = $_GET['totalRows_resultado'];
} else {
  $all_resultado = mysql_query($query_resultado);
  $totalRows_resultado = mysql_num_rows($all_resultado);
}
$totalPages_resultado = ceil($totalRows_resultado/$maxRows_resultado)-1;
mysql_free_result($resultado);
?>
<table border="2" cellpadding="2" cellspacing="6">
<tr>
<td>id_propiedad</td>
<td>ciudad</td>
<td>zona</td>
<td>localidad</td>
<td>tipo</td>
<td>tipo_inmueble</td>
<td>mtroscuadrados</td>
<td>habitaciones</td>
<td>precio</td>
<td>titulo</td>
</tr>
  <?php do { ?>
<tr>
<td><?php echo $row_resultado['id_propiedad']; ?></td>
<td><?php echo $row_resultado['ciudad']; ?></td>
<td><?php echo $row_resultado['zona']; ?></td>
<td><?php echo $row_resultado['localidad']; ?></td>
<td><?php echo $row_resultado['tipo']; ?></td>
<td><?php echo $row_resultado['tipo_inmueble']; ?></td>
<td><?php echo $row_resultado['mtroscuadrados']; ?></td>
<td><?php echo $row_resultado['habitaciones']; ?></td>
<td><?php echo $row_resultado['precio']; ?></td>
<td><?php echo $row_resultado['titulo']; ?></td>
</tr>
    <?php } while ($row_resultado = mysql_fetch_assoc($resultado));
 ?>
</table>
Madre mía, desde luego con tan pcas explicaciones y poniendo todo el código sin comentar, me lo pones difícil... tiene pinta que n estás rescuperando bien las variables que vienen en modo POST del formulario anterior.
Te recomiendo que para encontrar el problema, simplifiques todo esto a un solo campo, compruebas que funciona y luego ves avanzando, entiende que con un código puesto así, tan largo, se me haga complicado entender...

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas