Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   PHP (https://www.clubdelphi.com/foros/forumdisplay.php?f=15)
-   -   Como obtengo los resultados de un query (https://www.clubdelphi.com/foros/showthread.php?t=48948)

richy08 09-10-2007 00:13:29

Como obtengo los resultados de un query
 
Buenas tardes compañeros, tengo una duda de como puedo obtener los valores de un query en php, el query me devuelve un solo renglon de la base de datos y los distintos campos los quiero poner en comoponenetes html para que el usuario los vea pero no he encontrado como referenciar el resultado campo por campo gracias por cualquier comentario:D

enecumene 09-10-2007 00:22:28

Hola, Richy08, vale hombre ¿por que no posteas el codigo que mencionas y que estas utilizando?. asi se me hara mas facil ayudarte.

Saludos

richy08 09-10-2007 00:24:45

Código PHP:

<?php
 $link 
mysql_connect("localhost""root""");
 
mysql_select_db("boutiquepropeties");
 
$sql ="SELECT Property, Region, Region1, TypePropert, Location, Bedrooms, Parking, Furnished, Bathrooms, Views, Price, Wineceller, Dock, BeachClub, Beach, GuestHouse, Elevator, Tennis FROM properties where Property='$_POST[nombreB]'";
 
$result mysql_query($sql,$link );
 echo 
$result[0]['Property'];
?>
   <br>
   <br>
   <br>
   <table border="0" align="Center">
   <tr>
       Property
   </tr>
   <tr>
   <select name=nombre  class=Estilo2>
   <option selected><?php echo $_POST[nombreB]?></option>
   </select>
   </tr>
   </table>
   <table border="0" align="Center">
     <tr>
        Region
     </tr>
     <tr>
         <td>
          <select name="pais" class="Estilo2" disabled="Disabled">
           <option selected><?php echo $Region ?></option>
          </select>
         </td>
         <td>
         </td>
         <td>
          <select name="ciudad" class="Estilo2" disabled="Disabled">
           <option value="0">________________</option>
          </select>
         </td>
     </tr>
   </table>

esto es un fragmento del codigo lo que quieor hacer es referenciar $Region que es un campo que saco del query pero no doy con bola de ocmo obtener el valor, y mostrarlo al usuario en u select y asi lo haria con los demas campos del query gracias

enecumene 09-10-2007 00:28:50

Hola, de donde viene $Region? porque en el fragmento de codigo que posteaste porque no lo veo en parte.

Saludos.

richy08 09-10-2007 00:35:37

Cita:

Empezado por enecumene (Mensaje 237066)
Hola, de donde viene $Region? porque en el fragmento de codigo que posteaste porque no lo veo en parte.

Saludos.


Region es un campo que esta en el Query

Código PHP:

$sql ="SELECT Property, Region, Region1, TypePropert, Location, Bedrooms, Parking, Furnished, Bathrooms, Views, Price, Wineceller, Dock, BeachClub, Beach, GuestHouse, Elevator, Tennis FROM properties where Property='$_POST[nombreB]'"


ya lo intente asi $Region, $result[Region] pero no me da el contenido :confused:

enecumene 09-10-2007 00:41:41

Bueno, dejame ver si entendi, quieres llenar un combo con datos de regiones no? me imagino que tendras un tabla de regiones, si es asi debes crear otra consulta separada, codigo de ejemplo para que te des una idea despues lo ajustas:

Código PHP:

<select name="region" id="region">
    <option value="0">Eliga una region...</option>  
 <?
 
//obtengo los datos de la base
$sql "SELECT region FROM regiones order by region asc";
$r mysql_query($sql);
//mediante un while recorro todas las regiones y las imprimo en pantalla
while($row mysql_fetch_array($r)){ 
?> 
     <option value="<?=$row["region"]?>"><?=$row["region"]?></option>
<?}?> 
</select>

espero que te ayude.

Saludos.

richy08 09-10-2007 00:52:35

gracias enecumene pero eso lo lleno con javascript como son fijos no tengo necesidad de almacenarlos, ya resolvi la duda de los select ahora el problema es que tengo radio botones y check box en el codigo y no se como hacerle para que se chequien como los seletc posteo el codigo para ver si me puedes echar la mano
Código PHP:

<?php
 session_start
();
?>
<?php
 
if ($_SESSION['autentificado']=='SI')
 {
?>
<style type="text/css">
<!--
.Estilo1 {
        font-family: "Berlin Sans FB Demi";
        font-size: 20px;
        color: #000066;
}
.Estilo4 {
        font-family: "Berlin Sans FB Demi";
        color: #617c17;
        font-size: 25px;
}
.Estilo2 {
        font-family: "Berlin Sans FB Demi";
        color: #617c17;
}
-->
</style>
<html>
<body  bgcolor= #ece8b2>
<?php
 $link 
mysql_connect("localhost""root""");
 
mysql_select_db("boutiquepropeties");
 
$sql ="SELECT Property, Region, Region1, TypePropert, Location, Bedrooms, Parking, Furnished, Bathrooms, Views, Price, Wineceller, Dock, BeachClub, Beach, GuestHouse, Elevator, Tennis FROM properties where Property='$_POST[nombreB]'";
 
$result mysql_query($sql,$link );
 
$rs=mysql_fetch_array($result);
?>
  <form name="frmb" method="post" action="del_register.php">
   <br>
   <br>
   <br>
   <table border="0" align="Center">
   <tr>
       Property
   </tr>
   <tr>
   <select name=nombre  class=Estilo2>
   <option selected><?php echo $_POST[nombreB]?></option>
   </select>
   </tr>
   </table>
   <table border="0" align="Center">
     <tr>
        Region
     </tr>
     <tr>
         <td>
          <select name="pais" class="Estilo2" disabled="Disabled">
           <option selected><?php echo $rs[Region]; ?></option>
          </select>
         </td>
         <td>
         </td>
         <td>
          <select name="ciudad" class="Estilo2" disabled="Disabled">
           <option selected><?php echo $rs[Region1]; ?></option>
          </select>
         </td>
     </tr>
   </table>
   <br>
   <table align="Center">
      <tr>
       Type
      </tr>
      <tr>
        <td>
          <input type="radio" class="Estilo2" name="type" disabled="Disabled" value="Condominium" checked="true"><span class="txt">Condominium/Apartment</span><br />
          <input type="radio" class="Estilo2" name="type" disabled="Disabled" value="PentHouse"><span class="txt">PentHouse</span><br />
          <input type="radio" class="Estilo2" name="type" disabled="Disabled" value="Townhouse"><span class="txt">Townhouse</span>
        </td>
        <td>
          <input type="radio" class="Estilo2" name="type" disabled="Disabled" value="House"><span class="txt">House</span><br />
          <input type="radio" class="Estilo2" name="type" disabled="Disabled" value="Hacienda"><span class="txt">Hacienda</span><br />
          <input type="radio" class="Estilo2" name="type" disabled="Disabled" value="Lot"><span class="txt">Lot</span>
        </td>
        <td>
          <input type="radio" class="Estilo2" name="type" disabled="Disabled" value="Development Site"><span class="txt">Development Site</span><br />
          <input type="radio" class="Estilo2" name="type" disabled="Disabled" value="Fractional"><span class="txt">Fractional</span><br />
          <input type="radio" class="Estilo2" name="type" disabled="Disabled" value="Commercial"><span class="txt">Commercial</span>
        </td>
      </tr>
   </table>
   <br>
   <table align="Center">
   <tr>
    Location
   </tr>
   <tr>
    <td>
    <select name="location" class="Estilo2" disabled="Disabled">
    <option selected><?php echo $rs[Location]; ?></option>
     </option>
    </select>
    </td>
     <td>
      <select name="bedrooms" class="Estilo2" disabled="Disabled">
      <option selected><?php echo $rs[Bedrooms]; ?></option>
      </option>
      </select>
     </td>
     <td>
     </td>
     <td>
      <select name="Parking" class="Estilo2" disabled="Disabled">
       <option value="" selected="selected">Parking</option>
        <option selected><?php echo $rs[Parking]; ?></option>
       </option>
      </select>
     </td>
    </tr>
    </table>
    <br>
    <table align="Center">
    <tr>
     <td>
      <select name="Furnished" class="Estilo2" disabled="Disabled">
       <option selected><?php echo $rs[Furnished]; ?></option>
      </option>
      </select>
     </td>
     <td>
     </td>
     <td>
     <select name="Bathrooms" class="Estilo2" disabled="Disabled">
       <option value="" selected="selected">Bathrooms</option>
       <option selected><?php echo $rs[Bathrooms]; ?></option>
       </option>
     </select>
     </td>
     <td>
     <select name="View" class="Estilo2" disabled="Disabled">
        <option selected><?php echo $rs[Views]; ?></option>
       </option>
     </select>
     </td>
     <td>
     </td>
     </table>
     <br>
     <table align="center">
     <td>
     <select name="price" class="Estilo2" disabled="Disabled">
       <option selected><?php echo $rs[Price]; ?></option>
       </option>
     </select>
     </td>
     </tr>
     </table>
   <br>
   <table align="Center">
      <tr><td><input class="Estilo2" disabled="Disabled" type="checkbox" name="WineCeller" value="Yes"><span class="txt">Wine Celler</span><br /></td>
          <td><input class="Estilo2" disabled="Disabled" type="checkbox" name="Dock" value="Yes"><span class="txt">Dock</span><br /></td>
          <td><input class="Estilo2" disabled="Disabled" type="checkbox" name="BeachC" value="Yes"><span class="txt">Beach Club</span></td></tr>
      <tr><td><input class="Estilo2" disabled="Disabled" type="checkbox"  name="Tennis" value="Yes"><span class="txt">Tennis Court Access</span></td>
      <td><input class="Estilo2" disabled="Disabled" type="checkbox" name="Beach" value="Yes"><span class="txt">Beach Access</span></td>
      <td><input class="Estilo2" disabled="Disabled" type="checkbox" name="GuestHouse" value="Yes"><span class="txt">Guest House</span></td></tr>
      <td><input class="Estilo2" disabled="Disabled" type="checkbox" name="Elevator" value="Yes"><span class="txt">Elevator</span></td></tr>
   </table>
   <br>
   <center>
      <input type="submit" name="Submit" class="Estilo4" value="Delete">
      <input type="reset" name="Borrar" class="Estilo4" value="Clear">
   </center>
  </form>
 </body>
</html>
</body>
</html>
<?PHP
 
}
 else
 {
?>
    <SCRIPT LANGUAGE="javascript">
     location.href = "BoutiqueProperties.php";
    </SCRIPT>
<?PHP
 
}
?>



La franja horaria es GMT +2. Ahora son las 02:41:36.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi