How to generate a subcategory from the previous selection? Combobox

Asked

Viewed 42 times

0

I am developing a People Management system. I have an html form for the insertion of some data. I need to separate the positions in their respective sectors, ie the sector will be the category and the subcategories positions.

Below the code with the selection of sectors:

<select name="grava_colaborador_setor" name="grava_colaborador_setor" class="form-control">
<option value="">Selecione</option>
<?php
$result_cat_post = "SELECT * FROM tb_setores";
$resultado_cat_post = mysqli_query($mysqli, $result_cat_post);
while($row_cat_post = mysqli_fetch_assoc($resultado_cat_post) ) {
echo '<option value="'.$row_cat_post['id_setores'].'">'.$row_cat_post['nome'].'</option>'; }? </select>

Below is the table structure. I need to separate the categories according to the selected sector.

inserir a descrição da imagem aqui

  • The table is not normalized.. the relation is: A position can belong to several sectors. The way you structured the table you end up repeating the position information. I would make 3 tables: post, sectors, levels.

  • But I need to tie the sector to the post, I just want the value on the form to bring in the subcategory the positions as per the sector ID.

  • You first need to load 1 drop-down with the sectors, and then through a script in ajax, perform the dynamic load of the positions that belong to a sector, for this you will have to write a separate script that only brings the elements of the second drop-down (positions) by a parameter indicating the sector. See examples here https://stackoverflow.com/questions/2611277/populating-a-dropdown-list-in-php-dynamically

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.