plaincart, problem sa ucitavanjem menija sa kategorijama i pod kategorijama (RJESENO)

plaincart, problem sa ucitavanjem menija sa kategorijama i pod kategorijama (RJESENO)

offline
  • Pridružio: 08 Nov 2007
  • Poruke: 12
  • Gde živiš: Brcko, BiH

Napisano: 06 Mar 2013 13:58

Korisitim plaincart skriptu za izradu veb stranice i naisao sam na problem prilikom listanja menija sa podkategorijama...uvijek mi iz baze vuce prvu kategoriju i to ime mi se pojavljuje na kompletnom meniju npr.

ozvucenje
ozvucenje
ozvucenje
ozvucenje

a trebalo bi ovako

ozvucenje
aktivno
pasicno
rasvjeta

itd...

ovo su skripte koje su koristene

category functions
<?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($parent);           // 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, cat_description            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/no-image.png';       }              $cat[] = array('url'   => $_SERVER['PHP_SELF'] . '?lang=' . $_SESSION['language'] . '&c=' . $cat_id,                      'image' => $cat_image,                   'name'  => $cat_name,                   'description'  => $cat_description);     }        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($child, getChildCategories($categories, $catId));          }          }    }        return $child; } function fetchCategories() {     $sql = "SELECT cat_id, cat_parent_id, cat_name".$_SESSION['language'].", cat_image, cat_description".$_SESSION['language']."            FROM tbl_category          ORDER BY cat_id, cat_parent_id ";     $result = dbQuery($sql);         $cat = array();     while ($row = dbFetchAssoc($result)) {         $cat[] = $row;     }        return $cat; } ?>

category.php gdje treba da izlista
if (!defined('WEB_ROOT')) {    exit; } // get all categories $categories = fetchCategories(); // format the categories for display $categories = formatCategories($categories, $catId); ?> <ul> <?php foreach ($categories as $category) {    extract($category);    // now we have $cat_id, $cat_parent_id, $cat_name        $listId = '';         $url   = $_SERVER['PHP_SELF'] . "?lang=" . $_SESSION['language'] . "&c=$cat_id";        if ($cat_parent_id == 0) {       $cat_name = $cat_name. $_SESSION['language'];       $listId = ' id="cat"';    }    // for second level categories we print extra spaces to give    // indentation look    else {       $cat_name = '     ' . $cat_name. $_SESSION['language'];       $listId = ' id="subcat"';    }            // assign id="catactive" for the currently selected category    // this will highlight the category name        if ($cat_id == $catId) {       $listId = ' id="catactive"';    } ?> <li<?php echo $listId; ?>><a href="<?php echo $url; ?>"><?php echo $cat_name; ?></a></li> <?php } ?>

posto je stranica na vise jezika iz sesije vuce odabrani jezik, ako ne koristim sesiju za vise jezika lista meni kako treba.

ako neko moze pomoci unaprijed hvala...

Dopuna: 06 Mar 2013 15:42

rijesio sam ovo...morao sam staviti uslove za jezik u category.php

<?php if (!defined('WEB_ROOT')) {    exit; } // get all categories $categories = fetchCategories(); // format the categories for display $categories = formatCategories($categories, $catId); ?> <ul> <?php foreach ($categories as $category) {    extract($category);    // now we have $cat_id, $cat_parent_id, $cat_name        $listId = '';         $url   = $_SERVER['PHP_SELF'] . "?lang=" . $_SESSION['language'] . "&c=$cat_id";        if ($cat_parent_id == 0) {       if($_SESSION['language']=="en"){          $cat_name = $cat_nameen;       }       elseif($_SESSION['language']=="de")       {          $cat_name = $cat_namede;       }       else{          $cat_name = $cat_namesr;       }       $listId = ' id="cat"';    }    // for second level categories we print extra spaces to give    // indentation look    else {       if($_SESSION['language']=="en"){          $cat_name = '     ' . $cat_nameen;       }       elseif($_SESSION['language']=="de")       {          $cat_name = '     ' . $cat_namede;       }       else{          $cat_name = '     ' . $cat_namesr;       }       $listId = ' id="subcat"';    }            // assign id="catactive" for the currently selected category    // this will highlight the category name        if ($cat_id == $catId) {       $listId = ' id="catactive"';    } ?> <li<?php echo $listId; ?>><a href="<?php echo $url; ?>"><?php echo $cat_name; ?></a></li> <?php } ?> </ul>



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
Ko je trenutno na forumu
 

Ukupno su 2766 korisnika na forumu :: 57 registrovanih, 7 sakrivenih i 2702 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 20624 - dana 04 Apr 2026 04:18

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: 357magnum, Asteker, berste23, bojankrstc, Boris BM, Bubimir, Car89, coaaco, comi_pfc, CrveniSolaris, darionis, Dežurni pod palubom, Dimitrise93, Dovla 1980, Dusko_Dugousko, Džekson, Elvin, esko_hz, FOX, Foxdie, galerija, Glavonja049, Goran 0000, Grandmaster1, jeen yuhs, jodzula, kikisp, KizJ, Kobrim, Makarid, Manjane, mercedesamg, metallac777, milan.vukovic, Milometer, Mirage 2000N, OKT, Pauljxxx, pirke96, Radoslava, raf87, Resnica, RJ, SDsd, SlaKoj, Sonic, stegonosa, suton, tomo2, umpah-pah, v82, vathra, Voice1, vojnik švejk, x011, zelenajegulja, Zemunikola