Foros aprenderaprogramar.com

Libro de visitas, sugerencias y críticas => Comunidad => Mensaje iniciado por: brijan007 en 21 de Abril 2020, 08:37

Título: Seleccionar datos de mysql
Publicado por: brijan007 en 21 de Abril 2020, 08:37
buenos días,
estoy desarrollando una página inmobiliaria. he creado una base de datos mysql donde ingreso las propiedades mediante un archivo HTML que envía datos a otro PHP. en apariencia funciona, pero no me sirve. cuando un SELECT, me ofrece todas las propiedades ingresadas en la base de datos. necesito que me saque sólo aquellas que se correspondan con la selección efectuada, por ejemplo, si pongo "Marbella" necesito que me ofrezca tan solo las de Marbella.
pongo los códigos utilizados:
Código: [Seleccionar]
<table align=center font="Century Gothic" height=100 cellSpacing=0 cellPadding=1 width=800 border=0 style="HEIGHT: 100px; WIDTH: 800px" background="">


<form action="check-property.php" method="post">
 

  <tr>
 
    <td><font color=#0080ff
      face="Century Gothic"><strong>Property Title:</strong></font></td>
    <td style="WIDTH: 850px" width=850><input name="property_title"
      style="HEIGHT: 22px; WIDTH: 664px"><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font
      face="Century Gothic"><strong>Price:</strong></font></td>
    <td><input name="price" style="HEIGHT: 22px; WIDTH: 663px" size=23
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font color=#0080ff
      face="Century Gothic"><strong>Property Text:</strong></font></td>
    <td><input name="property_text" style="HEIGHT: 146px; WIDTH: 664px"
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
   <tr>
     <td>

  <p>
    <font color=#0080ff
      face="Century Gothic"><strong>Location:</strong></font></p></td>
    <td><select name="location" style="WIDTH: 664px">
      <option>Select your option</option>
      <option>Málaga</option>
  <option>Torremolinos</option>
  <option>Benalmádena</option>
  <option>Fuengirola</option>
  <option>Marbella</option>
  <option>Estepona</option>
    </select>
    </td></tr>
  <tr>
    <td><font color=#0080ff
      face="Century Gothic"><strong>Sub Location:</strong></font></td>
    <td><input name="sub_location" style="HEIGHT: 22px; WIDTH: 664px" size=21
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
     <td>

  <p>
    <font color=#0080ff
      face="Century Gothic"><strong>Property type:</strong></font></p></td>
    <td><select name="property_type" style="WIDTH: 664px">
      <option>Select your option</option>
      <option>Individual villa</option>
  <option>Town house</option>
  <option>Apartment</option>
  <option>Commercial</option>
  <option>Land</option>
  <option>Construction</option>
    </select>
    </td></tr>
  <tr>
    <td><font color=#0080ff
      face="Century Gothic"><strong>Status:</strong></font> </td>
    <td><input name="status" style="HEIGHT: 65px; WIDTH: 664px" size=22
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font
      face="Century Gothic"><strong>No. bedrooms:</strong></font></td>
    <td><input name="no_bedrooms" style="HEIGHT: 22px; WIDTH: 665px"
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font color=#0080ff
      face="Century Gothic"><strong>No. bathrooms:</strong></font></td>
    <td><input name="no_bathrooms" style="HEIGHT: 22px; WIDTH: 665px"
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font
      face="Century Gothic"><strong>Garage:</strong></font></td>
    <td><input name="garage" style="HEIGHT: 22px; WIDTH: 665px"
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font color=#0080ff
      face="Century Gothic"><strong>Area:</strong></font></td>
    <td><input name="area" style="HEIGHT: 22px; WIDTH: 665px" size=24
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font
      face="Century Gothic"><strong>Browse_images:</strong></font></td>
    <td><input name="browse_images" style="HEIGHT: 22px; WIDTH: 665px" size=22
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font color=#0080ff
      face="Century Gothic"><strong>Add video:</strong></font></td>
    <td><input name="ad_video" style="HEIGHT: 22px; WIDTH: 665px" size=21
     ></td></tr>
  <tr>
<td><font
face="Century Gothic"><strong>Select option:</strong></font></td>
        <td>
        <p><input type="checkbox" name="air_conditioning"> Air condition:<br>
        <input type="checkbox" name="bedding"> Bedding:<br>
        <input type="checkbox" name="balcony"> Balcony<br>
        <input type="checkbox" name="cable_TV"> Cable_TV:<br>
<input type="checkbox" name="internet"> Internet:<br>
    <input type="checkbox" name="parking"> Parking:<br>
<input type="checkbox" name="lift"> Lift:<br>
<input type="checkbox" name="pool"> Pool:<br>
        <input type="checkbox" name="dishwasher"> Dishwasher:<br>
<input type="checkbox" name="toaster"> Toaster:</p></td></tr>
      </table>
  <p align="center" ><input face="Century Gothic" name="guardar" value="Guardar" type="submit"><br></form></p>
ése es el archivo HTML, a continuación pongo el PHP
Código: [Seleccionar]
<?php
$connect
=mysql_connect("costadelsol","properties","realestate","khpscentexs");
if (
$connect) {
echo "conexion exitosa. <br />";

}
$ID$_POST ['id'];
$Reference$_POST ['reference'];
$Property_Title$_POST ['property_title'];
$Price$_POST ['price'];
$Property_Text$_POST ['property_text'];
$Location$_POST ['location'];
$Sublocation$_POST ['sub_location'];
$Property_Type$_POST ['property_type'];
$Status$_POST ['status'];
$Bedrooms$_POST ['no_bedrooms'];
        
$Bathrooms$_POST ['no_bathrooms'];
        
$Garage$_POST ['garage'];
$Area$_POST ['area'];
    $Browse_images$_POST ['browse_images'];
    $Add_video$_POST ['ad_video'];
    $Air_condition$_POST ['air_conditioning'];
    $Bedding$_POST ['bedding'];
    $Balcony$_POST ['balcony'];
    $Cable_TV$_POST ['cable_TV'];
    $Internet$_POST ['internet'];
    $Parking$_POST ['parking'];
    $Lift$_POST ['lift'];
    $Pool$_POST ['pool'];
    $Dish_Washer$_POST ['dishwaher'];
    $Toaster$_POST ['toaster'];
    
$consulta="SELECT * from properties values ('$ID','$reference','$property_title','$price','$property_text','$location','$sub_location','$property_type','$status','$no_bedrooms','$no_bathroomsno_bathrooms','$garage','$area', '$browse_images', '$ad_video', '$air_conditioning', ,'$bedding', '$balcony', '$cable_TV', '$internet', '$parking', '$lift', '$pool', '$dishwasher', '$toaster' )";

$resultado=mysqli_query($connect,$consulta);


$servername "localhost";
$username "realestate";
$password "khpscentexs";
$dbname "costadelsol";
function 
mostrarDatos ($resultados) {
if (
$resultados !=NULL) {
echo 
"- ID: ".$resultados['ID']."<br/>";
echo 
"- Reference: ".$resultados['reference']."<br/>";
echo 
"- Property_Title: ".$resultados['property_title']."<br/>";
echo 
"- Price: ".$resultados['price']."<br/>";
echo 
"- Property_Text : ".$resultados['property_text']."<br/>";
echo 
"- Location : ".$resultados['location']."<br/>";
echo 
"- Sub_Location: ".$resultados['sub_location']."<br/>";
echo 
"- Property_Type: ".$resultados['property_type']."<br/>";
echo 
"- Status: ".$resultados['status']."<br/>";
echo 
"- No_Bedrooms: ".$resultados['no_bedrooms']."<br/>";
echo 
"- No_Bathrooms: ".$resultados['no_bathrooms']."<br/>";
echo 
"- Garage: ".$resultados['garage']."<br/>";
echo 
"- Area: ".$resultados['area']."<br/>";
echo 
"- Browse_Images: ".$resultados['browse_images']."<br/>";
echo 
"- Add_Video: ".$resultados['ad_viseo']."<br/>";
echo 
"- Air_Condition: ".$resultados['air_conditioning']."<br/>";
echo 
"- Bedding: ".$resultados['bedding']."<br/>";
echo 
"- Balcony: ".$resultados['balcony']."<br/>";
echo 
"- Cable_TV: ".$resultados['cable_TV']."<br/>";
echo 
"- Internet: ".$resultados['internet']."<br/>";
echo 
"- Parking: ".$resultados['parking']."<br/>";
echo 
"- Lift: ".$resultados['lift']."<br/>";
echo 
"- Pool: ".$resultados['pool']."<br/>";
echo 
"- Dish_Washer: ".$resultados['dishwasher']."<br/>";
echo 
"- Toaster: ".$resultados['toaster']."<br/>";



echo 
"**********************************<br/>";}
else {echo 
"<br/>No hay más datos!!! <br/>";}
}
$link mysqli_connect($servername,$username,$password);
mysqli_select_db($link$dbname);
$tildes $link->query("SET NAMES 'utf8'"); //Para que se muestren las tildes correctamente
$result mysqli_query($link"SELECT * FROM properties");
while (
$fila mysqli_fetch_array($result)){
mostrarDatos($fila);
}
mysqli_free_result($result);
mysqli_close($link);
?>
gracias a quien me eche un cable, lo necesito
Título: Re:Seleccionar datos de mysql
Publicado por: brijan007 en 28 de Abril 2020, 16:09
buenos días,
estoy desarrollando una página inmobiliaria. he creado una base de datos mysql donde ingreso las propiedades mediante un archivo HTML que envía datos a otro PHP. en apariencia funciona, pero no me sirve. cuando un SELECT, me ofrece todas las propiedades ingresadas en la base de datos. necesito que me saque sólo aquellas que se correspondan con la selección efectuada, por ejemplo, si pongo "Marbella" necesito que me ofrezca tan solo las de Marbella.
pongo los códigos utilizados:
Código: [Seleccionar]
<table align=center font="Century Gothic" height=100 cellSpacing=0 cellPadding=1 width=800 border=0 style="HEIGHT: 100px; WIDTH: 800px" background="">


<form action="check-property.php" method="post">
 

  <tr>
 
    <td><font color=#0080ff
      face="Century Gothic"><strong>Property Title:</strong></font></td>
    <td style="WIDTH: 850px" width=850><input name="property_title"
      style="HEIGHT: 22px; WIDTH: 664px"><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font
      face="Century Gothic"><strong>Price:</strong></font></td>
    <td><input name="price" style="HEIGHT: 22px; WIDTH: 663px" size=23
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font color=#0080ff
      face="Century Gothic"><strong>Property Text:</strong></font></td>
    <td><input name="property_text" style="HEIGHT: 146px; WIDTH: 664px"
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
   <tr>
     <td>

  <p>
    <font color=#0080ff
      face="Century Gothic"><strong>Location:</strong></font></p></td>
    <td><select name="location" style="WIDTH: 664px">
      <option>Select your option</option>
      <option>Málaga</option>
  <option>Torremolinos</option>
  <option>Benalmádena</option>
  <option>Fuengirola</option>
  <option>Marbella</option>
  <option>Estepona</option>
    </select>
    </td></tr>
  <tr>
    <td><font color=#0080ff
      face="Century Gothic"><strong>Sub Location:</strong></font></td>
    <td><input name="sub_location" style="HEIGHT: 22px; WIDTH: 664px" size=21
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
     <td>

  <p>
    <font color=#0080ff
      face="Century Gothic"><strong>Property type:</strong></font></p></td>
    <td><select name="property_type" style="WIDTH: 664px">
      <option>Select your option</option>
      <option>Individual villa</option>
  <option>Town house</option>
  <option>Apartment</option>
  <option>Commercial</option>
  <option>Land</option>
  <option>Construction</option>
    </select>
    </td></tr>
  <tr>
    <td><font color=#0080ff
      face="Century Gothic"><strong>Status:</strong></font> </td>
    <td><input name="status" style="HEIGHT: 65px; WIDTH: 664px" size=22
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font
      face="Century Gothic"><strong>No. bedrooms:</strong></font></td>
    <td><input name="no_bedrooms" style="HEIGHT: 22px; WIDTH: 665px"
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font color=#0080ff
      face="Century Gothic"><strong>No. bathrooms:</strong></font></td>
    <td><input name="no_bathrooms" style="HEIGHT: 22px; WIDTH: 665px"
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font
      face="Century Gothic"><strong>Garage:</strong></font></td>
    <td><input name="garage" style="HEIGHT: 22px; WIDTH: 665px"
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font color=#0080ff
      face="Century Gothic"><strong>Area:</strong></font></td>
    <td><input name="area" style="HEIGHT: 22px; WIDTH: 665px" size=24
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font
      face="Century Gothic"><strong>Browse_images:</strong></font></td>
    <td><input name="browse_images" style="HEIGHT: 22px; WIDTH: 665px" size=22
     ><font
      face="Century Gothic"><strong></strong></font></td></tr>
  <tr>
    <td><font color=#0080ff
      face="Century Gothic"><strong>Add video:</strong></font></td>
    <td><input name="ad_video" style="HEIGHT: 22px; WIDTH: 665px" size=21
     ></td></tr>
  <tr>
<td><font
face="Century Gothic"><strong>Select option:</strong></font></td>
        <td>
        <p><input type="checkbox" name="air_conditioning"> Air condition:<br>
        <input type="checkbox" name="bedding"> Bedding:<br>
        <input type="checkbox" name="balcony"> Balcony<br>
        <input type="checkbox" name="cable_TV"> Cable_TV:<br>
<input type="checkbox" name="internet"> Internet:<br>
    <input type="checkbox" name="parking"> Parking:<br>
<input type="checkbox" name="lift"> Lift:<br>
<input type="checkbox" name="pool"> Pool:<br>
        <input type="checkbox" name="dishwasher"> Dishwasher:<br>
<input type="checkbox" name="toaster"> Toaster:</p></td></tr>
      </table>
  <p align="center" ><input face="Century Gothic" name="guardar" value="Guardar" type="submit"><br></form></p>
ése es el archivo HTML, a continuación pongo el PHP
Código: [Seleccionar]
<?php
$connect
=mysql_connect("costadelsol","properties","realestate","khpscentexs");
if (
$connect) {
echo "conexion exitosa. <br />";

}
$ID$_POST ['id'];
$Reference$_POST ['reference'];
$Property_Title$_POST ['property_title'];
$Price$_POST ['price'];
$Property_Text$_POST ['property_text'];
$Location$_POST ['location'];
$Sublocation$_POST ['sub_location'];
$Property_Type$_POST ['property_type'];
$Status$_POST ['status'];
$Bedrooms$_POST ['no_bedrooms'];
        
$Bathrooms$_POST ['no_bathrooms'];
        
$Garage$_POST ['garage'];
$Area$_POST ['area'];
    $Browse_images$_POST ['browse_images'];
    $Add_video$_POST ['ad_video'];
    $Air_condition$_POST ['air_conditioning'];
    $Bedding$_POST ['bedding'];
    $Balcony$_POST ['balcony'];
    $Cable_TV$_POST ['cable_TV'];
    $Internet$_POST ['internet'];
    $Parking$_POST ['parking'];
    $Lift$_POST ['lift'];
    $Pool$_POST ['pool'];
    $Dish_Washer$_POST ['dishwaher'];
    $Toaster$_POST ['toaster'];
    
$consulta="SELECT * from properties values ('$ID','$reference','$property_title','$price','$property_text','$location','$sub_location','$property_type','$status','$no_bedrooms','$no_bathroomsno_bathrooms','$garage','$area', '$browse_images', '$ad_video', '$air_conditioning', ,'$bedding', '$balcony', '$cable_TV', '$internet', '$parking', '$lift', '$pool', '$dishwasher', '$toaster' )";

$resultado=mysqli_query($connect,$consulta);


$servername "localhost";
$username "realestate";
$password "khpscentexs";
$dbname "costadelsol";
function 
mostrarDatos ($resultados) {
if (
$resultados !=NULL) {
echo 
"- ID: ".$resultados['ID']."<br/>";
echo 
"- Reference: ".$resultados['reference']."<br/>";
echo 
"- Property_Title: ".$resultados['property_title']."<br/>";
echo 
"- Price: ".$resultados['price']."<br/>";
echo 
"- Property_Text : ".$resultados['property_text']."<br/>";
echo 
"- Location : ".$resultados['location']."<br/>";
echo 
"- Sub_Location: ".$resultados['sub_location']."<br/>";
echo 
"- Property_Type: ".$resultados['property_type']."<br/>";
echo 
"- Status: ".$resultados['status']."<br/>";
echo 
"- No_Bedrooms: ".$resultados['no_bedrooms']."<br/>";
echo 
"- No_Bathrooms: ".$resultados['no_bathrooms']."<br/>";
echo 
"- Garage: ".$resultados['garage']."<br/>";
echo 
"- Area: ".$resultados['area']."<br/>";
echo 
"- Browse_Images: ".$resultados['browse_images']."<br/>";
echo 
"- Add_Video: ".$resultados['ad_viseo']."<br/>";
echo 
"- Air_Condition: ".$resultados['air_conditioning']."<br/>";
echo 
"- Bedding: ".$resultados['bedding']."<br/>";
echo 
"- Balcony: ".$resultados['balcony']."<br/>";
echo 
"- Cable_TV: ".$resultados['cable_TV']."<br/>";
echo 
"- Internet: ".$resultados['internet']."<br/>";
echo 
"- Parking: ".$resultados['parking']."<br/>";
echo 
"- Lift: ".$resultados['lift']."<br/>";
echo 
"- Pool: ".$resultados['pool']."<br/>";
echo 
"- Dish_Washer: ".$resultados['dishwasher']."<br/>";
echo 
"- Toaster: ".$resultados['toaster']."<br/>";



echo 
"**********************************<br/>";}
else {echo 
"<br/>No hay más datos!!! <br/>";}
}
$link mysqli_connect($servername,$username,$password);
mysqli_select_db($link$dbname);
$tildes $link->query("SET NAMES 'utf8'"); //Para que se muestren las tildes correctamente
$result mysqli_query($link"SELECT * FROM properties");
while (
$fila mysqli_fetch_array($result)){
mostrarDatos($fila);
}
mysqli_free_result($result);
mysqli_close($link);
?>
gracias a quien me eche un cable, lo necesito
Título: Re:Seleccionar datos de mysql
Publicado por: brijan007 en 28 de Abril 2020, 16:11
bueno, parece que he tenido bastantes visitas pero ninguna respuesta.
os comunico que he resuelto mi problema y, si alguien le interesa el cómo, puede dirigirse a mí y le contestaré con explicaciones.