Ver Mensaje Individual
  #3 (permalink)  
Antiguo 23/07/2013, 23:03
mikehove
 
Fecha de Ingreso: abril-2012
Ubicación: Argentina
Mensajes: 215
Antigüedad: 12 años
Puntos: 2
Respuesta: Modificar código - base de datos

Gracias cjxnet, estuve estudiando el sitio y la manera de hacer esto. Me sirvió mucho.
Ahora mostraré lo que avancé. Me trabé en el script para el menú.

Problema a corregir:


Código:
  $(document).ready(function()
            {
                $.getJSON("categories.php?callback=?",  function(data)
                {
					
                    $.each(data.Categories, function(i, category)
                    {
                       
                        var subjsondata='';
                        $.each(category.sub_categories, function(i, sub_categories)
                        { 
                          
                            subjsondata += "<li>"+sub_categories.nombreCategorias+"</li>";
					});
                 
                        var jsondata ="<li id='"+idCategorias+"' class='category'>"+category.nombreCategorias+"<ul id='hide"+category.idCategorias+"' class='hideul'>"+subjsondata+"</ul></li>";

                        $(jsondata).appendTo("#menu_ul");
                    });
                }
            );
});
El efecto que necesito es del menú-botón "Productos" de esta página: http://www.fravega.com/

Mi recorrido de arrays es así:

Código:
$user = 'root';
$pass = '';
$conn = new PDO('mysql:host=localhost;dbname=menu_categorias', $user, $pass);
 
$sql ='SELECT * FROM categorias ORDER BY lft';
$stmt = $conn->query($sql);
 
$categories = array();
$left = array();
$right = array();
$level = 0;
while ($row = $stmt->fetchObject()) {
    if (empty($right) === false) {
        $lastRight = end($right);
        if ($lastRight > $row->rgt) {
            $level = $level + 1;
        }
    }
    if (empty($left) === false) {
        $lastLeft = end($left);
        if ($row->lft - $lastLeft > 2) {
            $level = $level - 1;
        }
    }
    $categories[] = array('idCategorias' => $row->idCategorias,
                          'nombreCategorias' => $row->nombreCategorias,
                          'level' => $level);
    $left[] = $row->lft;
    $right[] = $row->rgt;	
}

 
echo '<ul>', "\n";
$count = count($categories);
if ($count == 1) {
    echo '<li>', $categories[0]['nombreCategorias'], '</li>', "\n";
} else {
    $i = 0;
    while (isset($categories[$i])) {
        echo '<li>', $categories[$i]['nombreCategorias'];
        if ($i < $count - 1) {
            if ($categories[$i + 1]['level'] > $categories[$i]['level'])
            {
                echo '<ul>', "\n";
            }
            else {
                echo '</li>', "\n";
            }
            if ($categories[$i + 1]['level'] < $categories[$i]['level']) {
                echo str_repeat('</ul></li>' . "\n",
                                $categories[$i]['level'] - $categories[$i + 1]['level']);
            }
        } else {      
            echo str_repeat('</ul></li>' . "\n", $categories[$i]['level']);
        }
    $i++;
    }
}
Imagen de la BD:


Imagen del recorrido de arrays:






mikepianist.- "Vivir es un desafío para valientes"