Soy computin, desde hace 5 años que tengo una discapacidad, estoy aprendiendo php y mysql.
Necesito ayuda en lo siguiente, estoy creando un formulario que tiene dos etiquetas select, una muestra regiones y la otra comunas que dependen de cada region.
Este es el formulario
<?php
include("../../conexion/conexion.php");
$regsql = "SELECT * FROM region ORDER BY 'cod_region' ASC";
$resultado = mysql_query($regsql) or die(mysql_error());
?>
<!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=utf-8" />
<title>Pruebas de funciones</title>
</head>
<body>
<table width="100%">
<tr>
<td><form id="form1" name="form1" method="post" action="">
<table width="100%">
<tr>
<td width="16%">Region</td>
<td width="84%"><label>
<select name="Region" id="Region">
<?php while($datos = mysql_fetch_array($resultado)) {?>
<option selected onclick="<?php $region = $datos['cod_region']; ?>"value="<?php echo $datos['cod_region']; ?>" > <?php echo $datos['cod_region']." - ".$datos['nom_region']; ?> </option>
<?php } ?>
</select>
</label></td>
</tr>
<tr>
<td>
</td>
<td>
<?php
echo "Region Nº : ".$region."<br>";
function comuna($region)
{
$sqlUpdate = "SELECT * FROM comuna WHERE cod_region_comuna = $region";
$resultado1 = mysql_query($sqlUpdate) or die (mysql_error());
$filas = mysql_num_rows($resultado1);
if ($filas == 0)
{
echo "no hay datos<br>";
}
else
{
//return $resultado1;
echo $filas;
}
}
comuna($region);
?>
</td>
</tr>
<tr>
<td>Comuna</td>
<td><label>
<select name="Comuna" id="Comuna">
<?php if($filas == 0): ?>
<option></option>
<?php else: ?>
<?php while($datos1 = mysql_fetch_array($comuna($region))) {?>
<option value="<?php echo $datos1['cod_comuna']; ?>"><?php echo $datos1['nom_comuna']; ?> </option>
<?php } ?>
<?php endif; ?>
</select>
</label></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
Solo muestra resultados de la primera region seleccionada.
Pueden ayudarme, estare muy agradecido...