Ver Mensaje Individual
  #3 (permalink)  
Antiguo 04/02/2009, 02:54
Avatar de b0zZy
b0zZy
 
Fecha de Ingreso: enero-2009
Ubicación: Francia
Mensajes: 28
Antigüedad: 15 años, 4 meses
Puntos: 0
Respuesta: Productos en Multiples Categorias

Hola quimfv,
Mira tengo 3 tablas,

tbl_product
pd_id
cat_id
cat_id2
cat_id3
....

tbl_category
cat_id
cat_name
...

many
pd_id
cat_id
cat_id2
cat_id3
...

Y esta query me funciona en sql,

Código PHP:
$sql 'SELECT tbl_product.pd_id, tbl_product.cat_id2, tbl_product.cat_id3, tbl_category.cat_id, 
CASE WHEN many.cat_id IS NULL 
THEN '
F'
ELSE '
T'
END AS selected
FROM tbl_category
CROSS JOIN tbl_product
LEFT JOIN many ON ( many.cat_id = tbl_product.cat_id
AND many.cat_id = tbl_product.cat_id ) 
WHERE (
tbl_product.cat_id = tbl_category.cat_id
)
ORDER BY `tbl_category`.`cat_id` ASC[...]'

Pero en mi category-functions.php,
Código PHP:
<?php
require_once 'config.php';

/*********************************************************
*                 CATEGORY FUNCTIONS 
*********************************************************/

/*
    Return the current category list which only shows
    the currently selected category and it's children.
    This function is made so it can also handle deep 
    category levels ( more than two levels )
*/
function formatCategories($categories$parentId)
{
    
// $navCat stores all children categories
    // of $parentId
    
$navCat = array();
    
    
// expand only the categories with the same parent id
    // all other remain compact
    
$ids = array();
    foreach (
$categories as $category) {
        if (
$category['cat_parent_id'] == $parentId) {
            
$navCat[] = $category;
        }
        
        
// save the ids for later use
        
$ids[$category['cat_id']] = $category;
    }    

    
$tempParentId $parentId;
    
    
// keep looping until we found the 
    // category where the parent id is 0
    
while ($tempParentId != 0) {
        
$parent    = array($ids[$tempParentId]);
        
$currentId $parent[0]['cat_id'];

        
// get all categories on the same level as the parent
        
$tempParentId $ids[$tempParentId]['cat_parent_id'];
        foreach (
$categories as $category) {
            
// found one category on the same level as parent
            // put in $parent if it's not already in it
            
if ($category['cat_parent_id'] == $tempParentId && !in_array($category$parent)) {
                
$parent[] = $category;
            }
        }
        
        
// sort the category alphabetically
        
array_multisort($ids,SORT_ASC);
    
        
// merge parent and child
        
$n count($parent);
        
$navCat2 = array();
        for (
$i 0$i $n$i++) {
            
$navCat2[] = $parent[$i];
            if (
$parent[$i]['cat_id'] == $currentId) {
                
$navCat2 array_merge($navCat2$navCat);
            }
        }
        
        
$navCat $navCat2;
    }


    return 
$navCat;
}

/*
    Get all top level categories
*/
function getCategoryList()
{
    
$sql "SELECT cat_id, cat_name, cat_image
            FROM tbl_category
            WHERE cat_parent_id = 0
            ORDER BY cat_name"
;
    
$result dbQuery($sql);
    
    
$cat = array();
    while (
$row dbFetchAssoc($result)) {
        
extract($row);
        
        if (
$cat_image) {
            
$cat_image WEB_ROOT 'images/category/' $cat_image;
        } else {
            
$cat_image WEB_ROOT 'images/Aucune image dispo.jpg';
        }
        
        
$cat[] = array('url'   => $_SERVER['PHP_SELF'] . '?c=' $cat_id,
                       
'image' => $cat_image,
                       
'name'  => $cat_name);

    }
    
    return 
$cat;            
}

/*
    Fetch all children categories of $id. 
    Used for display categories
*/
function getChildCategories($categories$id$recursive true)
{
    if (
$categories == NULL) {
        
$categories fetchCategories();
    }
    
    
$n     count($categories);
    
$child = array();
    for (
$i 0$i $n$i++) {
        
$catId    $categories[$i]['cat_id'];
        
$parentId $categories[$i]['cat_parent_id'];
        if (
$parentId == $id) {
            
$child[] = $catId;
            if (
$recursive) {
                
$child   array_merge($childgetChildCategories($categories$catId));
            }    
        }
    }
    
    return 
$child;
}

function 
fetchCategories()
{
    
$sql "SELECT cat_id, cat_parent_id, cat_name, cat_image, cat_description
            FROM tbl_category
            ORDER BY cat_name, cat_parent_id "
;
    
$result dbQuery($sql);
    
    
$cat = array();
    while (
$row dbFetchAssoc($result)) {
        
$cat[] = $row;
    }
    
    return 
$cat;
}

?>
me salen todos los productos en todas las categorias.
Un product puede tener varias categorias y quando se elija una categoria, pues que salga todos los productos de esa categoria.
Pero visto que estoy muy verde, pues no se si tengo que incluir un array o una function para que haga el paripe.
Me sigues !?
Gracias por tu ayuda

Última edición por b0zZy; 04/02/2009 a las 03:04