1
Gentlemen, I’d like some help. I need to popular a dropdown from a json file
{
"Categorias":
[
{
"categoria": "Automação",
"subcategoria": ["supervisório", "programação", "servidor", "hardware"]
},
{
"categoria": "CFTV",
"subcategoria": ["genetec", "servidor", "cabeamento", "ativo físico"]
},
{
"categoria": "Controle de acesso",
"subcategoria": ["sistema", "servidor", "controladora", "cabeamento/rede", "equip.físico"]
}
]
}
I managed to make the category key appear on dropdown
, but the subcategory occurs an error.
<div class="item form-group">
<label class='control-label col-md-3 col-sm-3 col-xs-12'>Categoria</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select class="form-control">
<?php
$arquivo = file_get_contents('teste.json');
$json = json_decode($arquivo);
foreach($json->Categorias as $registro):
?>
<option value="1"><?php echo $registro->categoria ?></option>
<?php
endforeach;
?>
</select>
</div>
</div>
<div class="item form-group">
<label class='control-label col-md-3 col-sm-3 col-xs-12'>Sub-categoria</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select class="form-control">
<?php
$arquivo2 = file_get_contents('teste.json');
$json2 = json_decode($arquivo);
foreach($json2->Categorias as $registro2):
?>
<option value="1"><?php echo $registro2->subcategoria ?></option>
<?php
endforeach;
?>
</select>
</div>
</div>
In the second dropdown
, an error message occurs:
(!) Notice: Array to string conversion
How do I create a dropdown
only with subcategory options?
worked perfectly. Thank you.
– Bruce
It is possible for me to display only the values of the first dropdown in the second dropdown?
– Bruce
Yes, it does, but that’s another question and another question has to be asked. OK?
– novic