Foros del Web » Programando para Internet » PHP »

Duda!!**Al mostrar registros de la bd mysql...***!!

Estas en el tema de Duda!!**Al mostrar registros de la bd mysql...***!! en el foro de PHP en Foros del Web. Que tal, Tengo una bd mysql donde tengo almacenados informacion sobre casas, rangos, etc... El caso es que tengo un formulario en php que te ...
  #1 (permalink)  
Antiguo 29/04/2008, 20:55
 
Fecha de Ingreso: febrero-2006
Mensajes: 858
Antigüedad: 18 años, 2 meses
Puntos: 4
Duda!!**Al mostrar registros de la bd mysql...***!!

Que tal,

Tengo una bd mysql donde tengo almacenados informacion sobre casas, rangos, etc...

El caso es que tengo un formulario en php que te da para buscar la propiedad por :
Tipo [bodega,casa,local,etc]
operacion [venta,renta]
rango [$x-$x]

El caso es que a la hora de mostrar los rangos no me muestra los registros..
Por ejemplo.. tengo una propiedad de 1,200,000
si pongo de 500,000 - 2,000,000 no muestra nada
pero si pongo de 1,000,000 - 1,500,000 si lo muestra...
(obvioo sin comas)
Entonces me he dado cuenta que muestra los registros que mas se acerque al precio...

Pero no se porque hace eso...
este es mi codigo que muestra..

[PHP]

if(isset($_POST['btn2']//Boton de buscar)) {
$result = mysql_query ("select * from propiedades where tipo = '$propiedad' and operacion = '$operacion'and precio between '".$_POST['r1']//Rango 1."' and '".$_POST['r2'].//Rango2"'");
if(mysql_num_rows($result)==0)
{
echo "Lo sentimos, no se encontró lo solicitado: <b> $propiedad/$operacion/$rango1-$rango2 </b>";
}
else
{
while ($row = mysql_fetch_array($result)) {
$codigo = $row["codigo"];
$tipo = $row["tipo"];
$operacion = $row["operacion"];
$ubicacion = $row["ubicacion"];
$precio = number_format($row["precio"]);
$descripcion = $row["descripcion"];
echo "<div align='center'>
<p>&nbsp;</p>
<table width='50%' border cellpadding='0' cellspacing='0'>[
//...........................................
</table>
</div>";
}
}
}
/PHP]

saludos y gracias
__________________
*La amistad se multiplica cuando se divide*
  #2 (permalink)  
Antiguo 30/04/2008, 00:37
Avatar de emiliodeg  
Fecha de Ingreso: septiembre-2005
Ubicación: Córdoba
Mensajes: 1.830
Antigüedad: 18 años, 7 meses
Puntos: 55
Re: Duda!!**Al mostrar registros de la bd mysql...***!!

primero r1 tiene q ser mayor a r2
$_POST['r1']=(int)$_POST['r1'];
$_POST['r2']=(int)$_POST['r2'];
if($_POST['r1']>$_POST['r2']){
$r=" precio >='".$_POST['r2']."' and precio<='".$_POST['r1']
}elseif(r1==r2)
{
$r="precio = '".$_POST['r1']."';
}else{
$r=" precio >='".$_POST['r1']."' and precio<='".$_POST['r2']
}

y agregas $r en
$result = mysql_query ("select * from propiedades where tipo = '$propiedad' and operacion = '$operacion'and $r");

corregi algunos detalels de sintaxis y tiene q salir andanod
__________________
Degiovanni Emilio
developtus.com
  #3 (permalink)  
Antiguo 30/04/2008, 11:50
 
Fecha de Ingreso: febrero-2006
Mensajes: 858
Antigüedad: 18 años, 2 meses
Puntos: 4
Re: Duda!!**Al mostrar registros de la bd mysql...***!!

Que tal gracias...

Pero creo que no funciono o yo lo puse mal..

mira asi quedó:

Código PHP:
    @$propiedad $_POST['propiedad'];
        @
$operacion $_POST['operacion'];
        @
$rango1 $_POST['r1'];
        @
$rango2 $_POST['r2'];
        
//
        
$_POST['r1']=(int)$_POST['r1'];
$_POST['r2']=(int)$_POST['r2'];
if(
$_POST['r1']>$_POST['r2']){
$r=" precio >='".$_POST['r2']."' and precio<='".$_POST['r1']."'";
}elseif(
r1==r2)
{
$r="precio = '".$_POST['r1']."'";
}else{
$r=" precio >='".$_POST['r1']."' and precio<='".$_POST['r2']."'";
//
        
if(isset($_POST['btn2'])) {
    
$result mysql_query ("select * from propiedades where tipo = '$propiedad' and operacion = '$operacion'and $r");
      if(
mysql_num_rows($result)==0

echo 
"Lo sentimos, no se encontró lo solicitado: <b> $propiedad/$operacion/$rango1-$rango2 </b>"

lo puedes checar aqui: http://franco-asociados.com/propiedadesprueba.php

saludos
gracias
__________________
*La amistad se multiplica cuando se divide*
  #4 (permalink)  
Antiguo 30/04/2008, 13:22
 
Fecha de Ingreso: febrero-2006
Mensajes: 858
Antigüedad: 18 años, 2 meses
Puntos: 4
Re: Duda!!**Al mostrar registros de la bd mysql...***!!

ayuuuuda porfaaaaaaaaaaaa
__________________
*La amistad se multiplica cuando se divide*
  #5 (permalink)  
Antiguo 01/05/2008, 10:30
 
Fecha de Ingreso: febrero-2006
Mensajes: 858
Antigüedad: 18 años, 2 meses
Puntos: 4
Re: Duda!!**Al mostrar registros de la bd mysql...***!!

ayudaa porfaa porfavoor no se que hacer
__________________
*La amistad se multiplica cuando se divide*
  #6 (permalink)  
Antiguo 01/05/2008, 10:48
Avatar de Carlojas  
Fecha de Ingreso: junio-2007
Ubicación: Shikasta
Mensajes: 1.272
Antigüedad: 16 años, 10 meses
Puntos: 49
Re: Duda!!**Al mostrar registros de la bd mysql...***!!

Y que es r1 y r2? verifica que no tengas errores en tu consulta

Código PHP:
$propiedad $_POST['propiedad']; 
$operacion $_POST['operacion']; 
$rango1 $_POST['r1']; 
$rango2 $_POST['r2']; 
$_POST['r1'] = (int)$_POST['r1']; 
$_POST['r2'] = (int)$_POST['r2']; 
if(
$_POST['r1'] > $_POST['r2']){ 
$r " precio >='".$_POST['r2']."' and precio<='".$_POST['r1']."'"
}elseif(
$_POST['r1'] == $_POST['r2']) // No las habias puesto como variables

$r "precio = '".$_POST['r1']."'"
}else{ 
$r " precio >='".$_POST['r1']."' and precio<='".$_POST['r2']."'"
// 
         
if(isset($_POST['btn2'])) { 
    
$result mysql_query ("select * from propiedades where tipo = '$propiedad' and operacion = '$operacion'and '$r'") or die("Error en query $result:" .mysql_error() ); 
      if(
mysql_num_rows($result)==0)  
{  
echo 
"Lo sentimos, no se encontró lo solicitado: <b> $propiedad/$operacion/$rango1-$rango2 </b>";  
}

Otra cosa que no alcanzo a entender se supone que tienes los rangos de precios en tu combo como es que haces para discriminar el valor del mismo por variables?
me refiero a $_POST['r1'] y $_POST['r2'], o sera que soy yo el que no entiende


Saludos.
  #7 (permalink)  
Antiguo 01/05/2008, 10:56
 
Fecha de Ingreso: febrero-2006
Mensajes: 858
Antigüedad: 18 años, 2 meses
Puntos: 4
Re: Duda!!**Al mostrar registros de la bd mysql...***!!

jaja no entendi a lo que te referiste... checate:

r1 y r2
son los rangos
que pones:
de $x(r1) - $x(r2)

es simple..

el problema es que no respeta esos rangos .. no se porque,...
los muestra si quiere... si no no ... asiii

y no se porque hace eso..

saludos
__________________
*La amistad se multiplica cuando se divide*
  #8 (permalink)  
Antiguo 01/05/2008, 11:00
Avatar de Carlojas  
Fecha de Ingreso: junio-2007
Ubicación: Shikasta
Mensajes: 1.272
Antigüedad: 16 años, 10 meses
Puntos: 49
Re: Duda!!**Al mostrar registros de la bd mysql...***!!

Disculpa no me habia fijado en eso, pero verificaste el código como te endique?



Saludos.
  #9 (permalink)  
Antiguo 01/05/2008, 11:23
 
Fecha de Ingreso: febrero-2006
Mensajes: 858
Antigüedad: 18 años, 2 meses
Puntos: 4
Re: Duda!!**Al mostrar registros de la bd mysql...***!!

Que tal. lo probe y me sale esto:

Error en query :You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '100000' and precio<='2000000''' at line 1

cual podria ser el error ?

saludos y gracias
__________________
*La amistad se multiplica cuando se divide*
  #10 (permalink)  
Antiguo 01/05/2008, 11:35
Avatar de Carlojas  
Fecha de Ingreso: junio-2007
Ubicación: Shikasta
Mensajes: 1.272
Antigüedad: 16 años, 10 meses
Puntos: 49
Re: Duda!!**Al mostrar registros de la bd mysql...***!!

Creo que no asignaste bien tus variables

Código PHP:
$propiedad $_POST['propiedad'];  
$operacion $_POST['operacion'];  
$rango1 = (int) $_POST['r1'];  
$rango2 = (int) $_POST['r2'];   
if(
$rango1 $rango2){  
$r " precio >= '$rango2' and precio <= '$rango1'";  
}elseif(
$rango1 == $rango2// No las habias puesto como variables 
{  
$r "precio = '$rango1'";  
}else{  
$r " precio >= '$rango1' and precio <= '$rango2'";
//  
          
if(isset($_POST['btn2'])) {  
    
$result mysql_query ("select * from propiedades where tipo = '$propiedad' and operacion = '$operacion'and '$r'") or die("Error en query $result:" .mysql_error() );  
      if(
mysql_num_rows($result)==0)   
{   
echo 
"Lo sentimos, no se encontró lo solicitado: <b> $propiedad/$operacion/$rango1-$rango2 </b>";   



Saludos.
  #11 (permalink)  
Antiguo 01/05/2008, 11:42
 
Fecha de Ingreso: febrero-2006
Mensajes: 858
Antigüedad: 18 años, 2 meses
Puntos: 4
Re: Duda!!**Al mostrar registros de la bd mysql...***!!

y sigue poniendo lo mismo... :(
Error en query :You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '100000' and precio <= '2000000''' at line 1

ayudaa porfa
__________________
*La amistad se multiplica cuando se divide*
  #12 (permalink)  
Antiguo 01/05/2008, 16:37
 
Fecha de Ingreso: febrero-2006
Mensajes: 858
Antigüedad: 18 años, 2 meses
Puntos: 4
Re: Duda!!**Al mostrar registros de la bd mysql...***!!

Que tal...

Ya no se que hacer .. estoo me urgee

Les muestro todo mi codigo para ver si encuentran algun error o porque pasa esto.... :(

Código PHP:
<form method='post' name='frm' action='PRUEBAPROPIEDADES.PHP'>
  <select name="propiedad" id="propiedad">
    <option value="CASA">Casa</option>
  <option value="BODEGA">Bodega</option>
  <option value="LOCAL">Local</option>
</select>
  <select name="operacion" id="operacion">
    <option value="VENTA">Venta</option>
  <option value="RENTA">Renta</option>
</select>
  <input name="r1" type="text" id="r1">
  <input name="r2" type="text" id="r2">
<input type="submit" name="btn2" value="Enviar">
</form>
<?
 
require_once("bd.inc.php");
$propiedad $_POST['propiedad'];   
$operacion $_POST['operacion'];   
$rango1 = (int) $_POST['r1'];   
$rango2 = (int) $_POST['r2'];    
if(
$rango1 $rango2){   
$r " precio >= '$rango2' and precio <= '$rango1'";   
}elseif(
$rango1 == $rango2
{   
$r " precio = '$rango1'";   
}
if(
$rango1 $rango2) {  
$r " precio between $rango1 and $rango2"
//   
           
if(isset($_POST['btn2'])) {   
    
$result mysql_query ("select * from propiedades where tipo = '$propiedad' and operacion = '$operacion'and '$r'") or die("Error en query $result:" .mysql_error() );   
      if(
mysql_num_rows($result)==0)    
{    
echo 
"Lo sentimos, no se encontró lo solicitado: <b> $propiedad/$operacion/$rango1-$rango2 </b><br>";  
echo 
"$result";  


else 

while (
$row mysql_fetch_array($result)) {
$codigo $row["codigo"];
$tipo $row["tipo"];
$operacion $row["operacion"];
$ubicacion $row["ubicacion"];
$precio number_format($row["precio"]);
$descripcion $row["descripcion"];
echo 
"<div align='center'>
<p>&nbsp;</p>
  <table width='50%' border cellpadding='0' cellspacing='0'>
    <!--DWLayoutTable-->
    <tr> 
      <td width='21' height='16'></td>
      <td width='2'></td>
      <td width='127'></td>
      <td width='11'></td>
      <td width='36'></td>
      <td width='16'></td>
      <td width='60'></td>
      <td width='147'></td>
      <td width='22'></td>
      <td width='12'></td>
    </tr>
    <tr> 
      <td height='21'></td>
      <td></td>
      <td colspan='3' rowspan='5' valign='top'><img src='CASA%20PRUEBA%20JAJA.JPG' width='167' height='125'></td>
      <td></td>
      <td colspan='2' valign='top'><p><font color='#000000' size='2' face='Trebuchet MS'>Propiedad: 
           $tipo </font></p></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height='21'></td>
      <td></td>
      <td></td>
      <td colspan='2' valign='top'><font color='#000000' size='2' face='Trebuchet MS'>Operaci&oacute;n: 
        $operacion  </font></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height='21'></td>
      <td></td>
      <td></td>
      <td colspan='2' valign='top'><font color='#000000' size='2' face='Trebuchet MS'>Precio: 
        $precio  </font></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height='13'></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height='58'></td>
      <td></td>
      <td>&nbsp;</td>
      <td colspan='3' valign='top'><font color='#000000' size='2' face='Trebuchet MS'> $descripcion </font></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td height='16'></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height='21'></td>
      <td colspan='2' valign='top'><a href='info.php?codigo=$codigo'><img src='boton2.jpg' width='119' height='19' border='0'></a></td>
      <td>&nbsp;</td>
      <td colspan='3' valign='top'><a href='imagenes.php'><img src='boton%201.jpg' width='119' height='19' border='0'></a></td>
      <td>&nbsp;</td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height='47'></td>
      <td>&nbsp;</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
  </table>
        </div>"
;
        }
}
}
      
?>
No se porque si pongo $_POST no me reconoce ... ya prove poniendoselo directamente al mysql_query osea sin post y si funciona .. pero pues yo necesito este buscador y ya no se como hacerle..

saludos
__________________
*La amistad se multiplica cuando se divide*
  #13 (permalink)  
Antiguo 02/05/2008, 11:54
 
Fecha de Ingreso: febrero-2006
Mensajes: 858
Antigüedad: 18 años, 2 meses
Puntos: 4
Re: Duda!!**Al mostrar registros de la bd mysql...***!!

alguien sabe porquee?
ayuudaa porfaaaa
__________________
*La amistad se multiplica cuando se divide*
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:49.