Código:
lo que quiero lograr en mi pagina, es que se cargue en un combo las categorias que tienen nivel 0 y las subcategorias que tienen nivel 1, osea cuando escojo por ejemplo en la opcion categoria autos en el combo subcategoria me salga, Honda, Wbm, Ferrari, etc... asi para abajo, obviamente dependiendo del nivel 0 que escoji....CODCATEGORIA varchar(20) PRI select,insert,update,references NOMBRE varchar(120) YES (NULL) select,insert,update,references NIVEL decimal(8,0) YES (NULL) select,insert,update,references FECHACREACION date YES (NULL) select,insert,update,references ORDEN decimal(8,0) YES (NULL) select,insert,update,references IMPORTANCIA decimal(8,0) YES (NULL) select,insert,update,references CATEGORIAPADRE varchar(20) YES (NULL) select,insert,update,references
hasta ahora tengo esto en php...
Código PHP:
function GetSelectCategoriaHTML($codcategoria='',$otra=0){
$html='';
$sel='<select name="cb_categoria" id="cb_categoria" class="seleccion">';
$db=conexion();
$sql="select codcategoria, nombre from categoria where nivel=0 order by nombre;";
$rs=$db->Execute($sql);
if($rs){
if($rs->RecordCount()>0){
$op='';
if($otra){
$op='<option value="0">-Seleccione la categoría-</option>';
}
while(!$rs->EOF){
if((strlen($codcategoria)>0)&&($rs->fields("codcategoria")==$codcategoria)){
$op.='<option value="'.$rs->fields("codcategoria").'" selected="selected">'.strtoupper($rs->fields("nombre")).'</option>';
} else {
$op.='<option value="'.$rs->fields("codcategoria").'">'.strtoupper($rs->fields("nombre")).'</option>';
}
$rs->MoveNext();
}
$sel.=$op.'</select>';
$html=$sel;
}
}
return $html;
}
function GetSelectSubCategoriaHTML($codcategoria='',$codsubcategoria='',$otra=0){
$html='';
$sel='<select name="cb_subcategoria" id="cb_subcategoria" class="seleccion" onchange="CambiaSubcategoria(this.form);">';
$db=conexion();
$sql="select codcategoria, nombre from categoria where nivel=1 and categoriapadre='".$codcategoria."' order by nombre";
$rs=$db->Execute($sql);
if($rs){
if($rs->RecordCount()>0){
$op='';
if($otra){
$op='<option value="0">-Seleccione la subcategoría-</option>';
}
while(!$rs->EOF){
if((strlen($codcategoria)>0)&&($rs->fields("codcategoria")==$codcategoria)){
$op.='<option value="'.$rs->fields("codcategoria").'" selected="selected">'.strtoupper($rs->fields("nombre")).'</option>';
} else {
$op.='<option value="'.$rs->fields("codcategoria").'">'.strtoupper($rs->fields("nombre")).'</option>';
}
$rs->MoveNext();
}
$sel.=$op.'</select>';
$html=$sel;
}
}
return $html;
}
Código HTML:
<form name="form1" method="post" action="estado.php"> <p>Fuente:<?php echo GetSelectFuenteHTML($idfuente); ?> <p>Categoria:<?php echo GetSelectCategoriaHTML($codcategoria); ?> </p> <p>Subcategoria:<?php echo GetSelectSubCategoriaHTML($codsubcategoria); ?> </p> ..... ... ....
porfis ayuden....
se los estaria eternamente agradecidos....