0
I need the variable $idestados
receive status id value
when an option is selected but I’m getting beat up by ajax and jquery so I want to know if you have a better option to do this.
The $anuncio
is a class that selects in the table bdd states through the selEstados()
and returns an array with all the information, it also has the selCidades(id_estado)
which does the same with bdd’s cities table but it receives the state id as parameter:
<select name="estados" id="estados" ">
<option value="0" selected disabled>Selecione um estado</option>
<?php
$estados=$anuncio->selEstados();
foreach ($estados as $estado){
echo '<option value="'.$estado['id'].'">'.$estado['sigla'].'-
'.$estado['nome'].'</option>';
}
?>
</select><br>
<select name="cidades" id="cidades" >
<option value="0">Selecione um estado primeiro...</option>
<?php
$cidades=$anuncio->selCidades($idestados);
foreach ($cidades as $cidade){
echo '<option value"'.$cidade['nome'].'">'.$cidade['nome'].'</option>';
}
?>
</select>
this code
require_once "anuncio.php";
$anuncio = new anuncio();
$estados= $anuncio->selEstados();
print_r($estados);
likewise the
require_once "anuncio.php";
$anuncio = new anuncio();
$cidades= $anuncio->selCidades();
print_r($cidades);
will produce the same effect but with city names and state id instead of the acronym
Edit the question and post the rest of your code to help.
– LipESprY
After PHP processes the information, it is not possible to change its variables. For this you should use AJAX (post as you are trying) or sending the information via a form.
– Valdeir Psr
I deleted the code I had made when it didn’t work, could you give me an example of how it would work based on the code I passed up there?
– Rodrigo Marques