He encontrado un código que hace justo lo que necesito pero no logro adaptarlo
Tengo dos Combobox que dependen de un campo fecha en la base de datos.
lo que necesito es filtrar los datos primero por año y luego por mes según el usuario seleccione el año o el mes.
El código que tengo es el siguiente
Código PHP:
<html>
<html>
<head>
<title>pagina1.php</title>
</head>
<body>
<form method="post" action="pagina2.php">
<table width="70%" border="0" align="center">
<?php
// Me conecto a la base de datos
mysql_connect("localhost","user","1234");
mysql_select_db("base");
// Declaro la variable $anioant que es la que me va a indicar si hay que volver a cargar los datos de los meses
$anio = 'YEAR(fecha)';
$mes ='Month (anio)';
$anioant=$anio;
print ("
<input type=\"hidden\" name=\"anioant\" value=\"$anioant\">
<tr>
<td><div align=\"right\"><strong>Año:</strong></div></td>
<td><select name=\"fecha\" onchange=\"submit();\">
");
//Muestra el combobox de los meses una vez que se haya elegido el año, no antes
if (!isset($anio)){
print ("<option selected>Seleccione el año</option>");
$anio="0";
}
$sql="select * from mareas";
$res=mysql_query($sql);
while($fila=mysql_fetch_array($res)){
print("<option value=\"$fila[fecha]\"");
if ($fila[fecha] == $anio) {
print ("selected");
}
print(">$fila[fecha]</option>\n");
}
print("</select></td></tr>");
if ($anio!="0"){
print("
<tr>
<td><div align=\"right\"><strong>Mes:</strong></div></td>
<td><select name=\"prov\">
");
$sqlprov="select * from provincias where fecha='$anio' order by 2";
$resprov=mysql_query($sqlprov);
while($filaprov=mysql_fetch_array($resprov)){
print("<option value=\"$filaprov[id_prov]\">$filaprov[prov]</option>");
}
print("
</select>
</td>
</tr>
");
}
?>
</table>
</form>
</body>
</html>
Supongo que tengo un lio con las variables y por eso no me sale como necesito que salgo.
Alguien me podria ayudar?
Muchas gracias.