Ver Mensaje Individual
  #6 (permalink)  
Antiguo 13/08/2010, 08:29
Sirrohan
 
Fecha de Ingreso: julio-2010
Mensajes: 275
Antigüedad: 13 años, 10 meses
Puntos: 21
Respuesta: Select editable

Te voy a colgar un ejemplo, es implementando Javascript, PHP y Mysql. Espero que te sirva. el contenido de conexion_bd.php lo tienes en el post anterior

Código HTML:
<html>
<head>
<?php
/*------------------------------------------------------------------*
'|  PROYECTO: Precios de estancia en playas de Barcelona
'|  ARCHIVO: index.php
'|  FECHA: 10/05/2009
'|  PARTE DEL PROYECTO: selector de playas
'|  AUTOR: Hiram Loreto
'+------------------------------------------------------------------*/

include ("conexion_bd.php");

$Conecta = new Conexion_bd();
$Conecta->Gestion("SELECT id_playa, playa, precio FROM playas ORDER BY id_playa");
?>

<script language = "JavaScript" type="text/javascript">
<!-- 

//mezclamos javascript con php

// Funcion para los precios de las playas
function segunda_lista(playa) {
//mediante etiquetas php creamos el bucle que recorre la tabla
	<?
	 while ($Rows = mysql_fetch_array($Conecta->Query)){
	?>
	//mediante etiquetas php asignamos valor a las variables javascript
		precio = "<?= $Rows["precio"]; ?>";
		idplaya = "<?= $Rows["id_playa"]; ?>";
		//comprobamos que sea la playa elegida y le damos el precio
		if (idplaya == playa) {
		  form1.precio_playa.value=precio;
		  form1.precio_total.value=eval(form1.dias.value*precio);
		 }
		<?
	 }
	?>
}

//Si el usuario cambia el numero de dias recalculamos el valor
function cambio_dias () {
  form1.precio_total.value=eval(form1.dias.value*form1.precio_playa.value);
}

 -->
</script>
</head>
<body>
<h3 align="center"><strong>Seleccione playa, dias y precios:</strong></h3>
<form id="form1" name="form1" method="post" action="index.php">
<table width="60%" border="0" cellpadding="3" cellspacing="1" align="center">
  <tr>
	<td align="left" colspan="2">
	  Playa: &nbsp;</td>
	<td align="left" colspan="6">
	  <select size="1" id="playa" name="playa" onchange = "javascript:segunda_lista(playa.value);">
	  <option value="none">Seleccione una playa</option>
	  <? 
			$Conecta2 = new Conexion_bd();
			$Conecta2->Gestion("SELECT id_playa, playa, precio FROM playas ORDER BY id_playa");
			while ($Rows = mysql_fetch_array($Conecta2->Query)){
	  ?>
	  <option value="<?= $Rows["id_playa"]; ?>"><?= $Rows["playa"]; ?></option>
	  <?
			}
	  ?>
	</select>
	</td>
  </tr>
	<tr>
	<td colspan="2" align="left" bgcolor="#CCCCCC">Días: &nbsp;</td>
	<td colspan="6" align="left" bgcolor="#CCCCCC">
	  <input type="text" id="dias" name="dias" size="10" value="7" onchange = "javascript:cambio_dias();"> (Estancia mínima 7 días)
	</td>
  </tr>  
	<tr>
	<td colspan="2" align="left">Precio: &nbsp;</td>
	<td colspan="6" align="left">
	  <input type="text" id="precio_playa" name="precio_playa" size="10" disabled="disabled"> (por día)
	</td>
  </tr>
	<tr>
	<td colspan="2" align="left" bgcolor="#CCCCCC">Precio total estancia: &nbsp;</td>
	<td colspan="6" align="left" bgcolor="#CCCCCC">
	  <input type="text" id="precio_total" name="precio_total" size="10" disabled="disabled"> (por día)
	</td>
  </tr>
  <tr>
	<td colspan="8" align="center"><input type="submit" name="pedir" value="Solicitar" /></td>
  </tr>
</table>
</form>
</body>
</html> 
Y este sería el SQL
Código:
# MySQL-Front 3.2  (Build 14.3)

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES latin1 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='SYSTEM' */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */;
/*!40101 SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES */;
/*!40103 SET SQL_NOTES='ON' */;


# Host: localhost    Database: prueba_playas
# ------------------------------------------------------
# Server version 5.0.67-community-nt

DROP DATABASE IF EXISTS `prueba_playas`;
CREATE DATABASE `prueba_playas` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_spanish_ci */;
USE `prueba_playas`;

#
# Table structure for table playas
#

CREATE TABLE `playas` (
  `id_playa` int(11) unsigned NOT NULL auto_increment,
  `playa` varchar(75) collate latin1_spanish_ci default NULL,
  `precio` double(11,2) unsigned default NULL,
  PRIMARY KEY  (`id_playa`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci;

#
# Dumping data for table playas
#

LOCK TABLES `playas` WRITE;

INSERT INTO `playas` VALUES (1,'playa 1',25.56);
INSERT INTO `playas` VALUES (2,'playa 2',3.99);
INSERT INTO `playas` VALUES (3,'playa 3',15.67);
INSERT INTO `playas` VALUES (4,'playa 4',18.5);
INSERT INTO `playas` VALUES (5,'playa 5',199.99);
INSERT INTO `playas` VALUES (6,'playa 6',201);

UNLOCK TABLES;

/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;