Oi pessoal!
Estou criando um sistema de select & option de categorias e subcategorias, onde o javascript busca o ID de uma categoria e quero usar esse valor para filtrar as subcategorias do segundo select.
Para isso, eu queria buscar o array com os IDs das categorias (criado na View) pelo Model para usa-lo como filtro no select, concatenando o array com a coluna ‘parent_id’ (determina as subcategorias de cada categoria).
Seguem os códigos:
VIEW:
<select name="product-category" id='product-category' size='10' class="form-control" onclick="myFunction()">
<?php foreach($product_categories as $product_category){ ?>
<option value="<?php echo $product_category['category_id'] ?>" ><?php echo $product_category['name'] ?></option>
<?php } ?>
</select>
<select name='product-subcategory1' id="product-subcategory1" size='10' class="form-control">
<?php foreach($product_subcategories1 as $product_subcategory1){ ?>
<option value="<?php echo $product_subcategory1['category_id'] ?>"><?php echo $product_subcategory1['name'] ?></option>
<?php } ?>
</select>
<script>
function myFunction() {
document.getElementById("product-category").click();
var product_category = document.getElementById("product-category").value;
alert(product_category);window.location.assign("index.php?
route=account/customerpartner");
}
function myFunction1() {
document.getElementById("product-subcategory1").click();
var product_subcategory1 = document.getElementById("product-
subcategory1").value;
alert(product_subcategory1);
}
</script>
MODEL:
public function getSubcategory1($data= array()) {
$sql = "SELECT name, category.category_id,
category_path.level,category.parent_id FROM category_description
LEFT JOIN category ON category_description.category_id =
category.category_id LEFT JOIN category_path ON
category_description.category_id = category_path.category_id WHERE
category_description.language_id = 2 AND category_path.level = 1 AND
category.parent_id IN (". ARRAY JAVA AQUI! .") ORDER BY
category_description.name ASC";
$query = $this->db->query($sql);
return $query->rows;
}
Alguém tem alguma ideia de como posso fazer isso?
Agradeço desde já a ajuda.