my query is as follows, I have a database of table "departments" that presents the following columns: department, province, district. with this I make a call to the database to be able to offer options to the 3 SELECT that I present. So what I'm looking for is that the select conjugate with each other, that is, this unblocked department and that this blocked province and district. then when you select a department, province is unblocked, and you only show me the provinces of that department, and the same when you select province, show me the districts of that province.
something like this:
and the code is as follows:
<!DOCTYPE html>
<html>
<head>
<title>SELECT</title>
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
</head>
<body>
<center>
<label>Departamento: </label>
<select name="sss" id="sss" onchange="this.form.submit()">
<option value="">Seleccione una opcion</option>
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("informacion",$con);
mysql_set_charset("utf8",$con);
$consulta1= mysql_query("SELECT distinct(departamento) as x FROM departamentos ");
while($data= mysql_fetch_array($consulta1)){
$depa=$data['x'];
echo "<option value='".$depa."' $selected>".$depa."</option>";
}
?>
</select>
<br><br>
<label>Provincia: </label>
<select name="ttt" id="ttt" onchange="this.form.submit()">
<option value="">Seleccione una opcion</option>
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("informacion",$con);
mysql_set_charset("utf8",$con);
$consulta2= mysql_query("SELECT distinct(provincia) as x FROM departamentos where departamento='LIMA'");
while($data= mysql_fetch_array($consulta2)){
$provi=$data['x'];
echo "<option value='".$provi."' $selected>".$provi."</option>";
}
?>
</select>
<br><br>
<label>Distrito: </label>
<select name="vvv" id="vvv">
<option value="">Seleccione una opcion</option>
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("informacion",$con);
mysql_set_charset("utf8",$con);
$consulta3= mysql_query("SELECT distinct(distrito) as x FROM departamentos where departamento='LIMA' AND provincia='LIMA'");
while($data= mysql_fetch_array($consulta3)){
$distr=$data['x'];
echo "<option value='".$distr."' $selected>".$distr."</option>";
}
?>
</select>
</center>
</body>
</html>
Could the conjugation be done? Is it necessary to do with SELECT or can it be done differently?