I have 2 selects: #pais and #status.
I want you to populate the state with only the states of that country, which are stored in a mysql table:
tabela_paises
id|pais
1|brasil
tabela_estados
id|idpais|estado
1| 1 |São Paulo
the country select already has 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 I do not know how to do to get the id of the country as a 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);