Ver Mensaje Individual
  #18 (permalink)  
Antiguo 22/03/2008, 11:15
Avatar de rogertm
rogertm
Mod->Cuba
 
Fecha de Ingreso: julio-2005
Ubicación: /home/Cuba/Habana/rogertm/
Mensajes: 2.922
Antigüedad: 18 años, 9 meses
Puntos: 638
Re: Crear menu con Categorias y SubCategorias usando MySQL y PHP

niño...! pero si hace dias te dije que tenias que cambiar solo una linea, que asi te funcionaria, nu lo viste??? pues repetimos.

tienes este codigo:
Código PHP:
<?php
mysql_select_db
("secciones");

$sqlQuery mysql_query("SELECT categorias.*, subcategorias.* FROM categorias, subcategorias
                         WHERE categorias.categoria_id = subcategorias.categoria_id
                         ORDER BY subcategorias.subcategoria_id ASC"
$db) or die(mysql_error());

$categoria "";
$categorias = array();
$pos 0;

while (
$row mysql_fetch_object($sqlQuery)){
    if(
$categoria != $row -> categoria_id){
        
//echo "<h1>".$row -> categoria_nombre."...</h1>";
        
$categoria $row -> categoria_id;
        
$pos array_push$categorias,  array( $categoria, array() ) );
    }    
    
$categorias[$pos][1][] = array($row->subcategoria_id$row -> subcategoria_nombre);
    
}

foreach (
$categorias as $categoria)
{
    if( !empty( 
$categoria[0] ) ) {
           echo 
"<h1>" $categoria[0] . "</h1>";
    }
    if (
count($categoria[1]) > 0)
    {
        echo 
"<ul>";
        foreach (
$categoria[1] as $subCat)
        {
            echo 
"<li><a href='index.php?mod=categorias&amp;categoria_id=" $subCat[0] . "'>" .
                
$subCat[1] . "</a></li>";
        }
        echo 
"</ul>";
    }
}
?>
que te devuelve esto:

1
* Subcategoria 1
* Subcategoria 2
* Subcategoria 3

2
* Subcategoria 1
* Subcategoria 2

siendo 1 y 2 el id de cada categoria, lo unico que tienes que hacer es cambiar esta linea:
Código PHP:
<?php
$categoria 
$row -> categoria_id;
?>
por esta:
Código PHP:
<?php
$categoria 
$row -> categoria_nombre;
?>
y ya esta, prueba a ver, que cuando te lo puse ni siquiera dijiste si te funciono o no

saludos y suerte
__________________
Friki y Blogger por Cuenta Propia:213
Twenty'em: Theming is Prose