Ver Mensaje Individual
  #10 (permalink)  
Antiguo 29/03/2007, 09:00
Avatar de Saruman
Saruman
 
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
Re: crear un arbol de categorías con checkbox o con un select.

listo, aquí esta el ejemplo.

modifique un poco la función, asi que fijate bien....

saludos

Código PHP:
function crearArbol($tabla,$id_field,$show_data,$link_field,$parent,$prefix){
    
/*Armar query*/
    
$sql='select * from '.$tabla.' where '.$link_field.'='.$parent;

    
/*Asumiendo que se usa MySQL (se puede cambiar facilmente a otra db)*/
    
if ($parent != && $prefix == ''$prefix '--';
    
$rs=@mysql_query($sql);
    if(
$rs){
           
/*Recorrer todos las entradas */
           
while($arr=mysql_fetch_array($rs)){
        
/* Imprimir campo a mostrar*/
                
echo('<option value="' $arr[$id_field] . '">' $prefix $arr[$show_data] . '</option>' chr(13));
                
//echo($prefix.$arr[$show_data].'<br>');
        
        /* imprimir arbol the "hijos" de este elemento*/
                
crearArbol($tabla,$id_field,$show_data,$link_field,$arr[$id_field],$prefix.$prefix);
           }
    }    
}

echo(
'<select name="nombre">' chr(13));
crearArbol('localizacion','id_localizacion','localizacion','id_padre',0,'');
echo(
'</select>'); 
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.