0
I have 2 selects: #parents and #status.
I want that when selecting the country, it populates the state only with the states of that country, which are written in a mysql table:
tabela_paises
id|pais
1|brasil
tabela_estados
id|idpais|estado
1| 1 |São Paulo
the country select already contains a query, the values of the country table
$db =& JFactory::getDBO();
$db->setQuery("SELECT pais FROM tabela_paises ORDER BY pais ASC");
$results = $db->loadObjectList();
$items[] = "- Nenhum -";
foreach ($results as $res){
$items[] = $res->pais;
}
return implode("\n",$items);
But for the state do not know how to get the country id as filter, I thought of something like below, but in this case the id is fixed, it needs to be dynamic
$db =& JFactory::getDBO();
$db->setQuery("SELECT estado FROM tabela_estados WHERE idpais = 1 ORDER BY estado ASC");
$results = $db->loadObjectList();
$items[] = "- Nenhum -";
foreach ($results as $res){
$items[] = $res->estado;
}
return implode("\n",$items);
How are you doing to send the information to the server? Is the whole page loaded or by ajax? You need to define how the status id should arrive per parameter in the request.
– Machado da Costa