Hola,
Realizo una consulta de paises con un combo realizado con Dreamweaver.
Este me carga un segundo combo con ciudades.
Al clicar el primer combo de paise ej (España), me abre el segundo combo de ciudades (Barcelona, Madrid)...
Me interesaría que al clicar sobre una ciudad (del segundo), por ejemplo Barcelona, me cargue todas las ciudades de la BD mysql de Barcelona y me las liste.
El código actual en PHP
Un saludo y espero vuestras respuestas,
Muchas gracias.
__________
Código PHP:
Ver original<?php require_once('../Connections/contactos.php'); ?>
<?php require_once('../Connections/contactos.php'); ?>
<?php require_once('../Connections/contactos.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
}
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;
}
}
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
}
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;
}
}
$query_Paises = "SELECT * FROM paises";
$colname_ciudad = "-1";
if (isset($_POST['id_pais'])) { $colname_ciudad = $_POST['id_pais'];
}
$query_ciudad = sprintf("SELECT id_ciudad, ciudad FROM ciudades WHERE id_pais = %s", GetSQLValueString
($colname_ciudad, "int"));
$query_Recordset1 = "SELECT * FROM contactos";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<p>
<select name="id_pais" id="id_pais" onChange="submit()">
<option value=""
<?php if (!(strcmp("", $_POST['id_pais']))) {echo "selected=\"selected\"";} ?>>Pais</option>
<?php
do {
?><option value="
<?php echo $row_Paises['id_pais']?>"
<?php if (!(strcmp($row_Paises['id_pais'], $_POST['id_pais']))) {echo "selected=\"selected\"";} ?>>
<?php echo $row_Paises['pais']?></option>
<?php
if($rows > 0) {
}
?>
</select>
</p>
<p>
<select name="id_ciudad" id="id_ciudad">
<option value=""
<?php if (!(strcmp("", $_POST['id_ciudad']))) {echo "selected=\"selected\"";} ?>>Ciudad</option>
<?php
do {
?><option value="
<?php echo $row_ciudad['id_ciudad']?>"
<?php if (!(strcmp($row_ciudad['id_ciudad'], $_POST['id_ciudad']))) {echo "selected=\"selected\"";} ?>>
<?php echo $row_ciudad['ciudad']?></option>
<?php
if($rows > 0) {
}
?>
</select>
</p>
</form>
</body>
</html>
<?php
?>