Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Smarty] Pokazuje co nie trzeba
Forum PHP.pl > Forum > Gotowe rozwiązania > Systemy szablonów
Lee
Mam problem ze smarty otóż mam tabelę "category"
struktura
Cytat
ID || NAME || DESCRIPTION || IMAGE || MAIN_CATEGORY

przykładowe wpisy - 2
Cytat
1 || Internet || Wszystko o internecie || /uploads/category/image.jpg ||
2 || Strony WWW || O stronach WWW || || Internet

W takim "układzie" Strony WWW są podkategorią dla Internetu, no i wyświetlam sobie same kategorie główne (tylko Internet) i jest ok, ale jak już wejdę, w tą kategorię i chce wyświetlić podkategorie (tylko Strony WWW) to pokazuje mi i Internet i Strony WWW jako podkategorie, robię to tak w pliku
category.php mam kod
  1. <?php
  2. $db_query = "SELECT * FROM $tbl_category WHERE id='".$_GET['id']."'";
  3. $mysql -> fetch_assoc($db_query);
  4. $smarty -> assign('category', $mysql -> row);
  5. foreach ($mysql -> row as $Category){
  6. $mysq = new MySQL;
  7. $db_query = "SELECT * FROM $tbl_category WHERE main_category='".$Category['name']."' AND main_category<>''";
  8. $mysql -> fetch_assoc($db_query);
  9. $smarty -> assign('subCategory', $mysql -> row);
  10. }
  11. ?>

i w pliku category.tpl mam
  1. <div class="text_03">Kategoria: {foreach from=$category item=category}<b>{$category.name}</b>{/foreach} / </div>
  2. <table cellspacing="0" cellpadding="0" rules="all" style="margin: auto; border: 1px solid #000000; width: 400px">
  3. <tr>
  4. <td class="text_01" style="background-color: {$color_2}; background-image: {$news_bg_1}">Podkategorie</td>
  5. </tr>
  6. {if !empty($subCategory)}
  7. {foreach from=$subCategory item=subCategory}
  8. <tr>
  9. <td class="text_04" style="background-color: {$color_2}"><a href="category.php?id={$subCategory.id}">{$subCategory.name}</a> - <i>{$subCategory.description}</i></td>
  10. </tr>
  11. {/foreach}
  12. {else}
  13. <tr>
  14. <td class="text_04" style="background-color: {$color_2}">Brak podkategorii</td>
  15. </tr>
  16. {/if}
  17. </table>

co mam źle :| wg. mnie powinno działać normalnie ohmy.gif
Skobi
Po pierwsze dodaj w pliku .php:
  1. <?php
  2. $smarty->debugging = true;
  3. ?>

i zobacz czy wszystkie dane przesylane do smartow sa poprawne.

Mam jeszcze watpliwosc co do tego fragmentu kodu:
  1. <?php
  2. foreach ($mysql -> row as $Category)
  3. {
  4. $smarty -> assign('subCategory', $mysql -> row);
  5. }
  6. ?>

przeciez w kazdej iteracji petli nadpisujesz sobie wpis poprzedni, czyli
  1. <?php
  2. $smarty -> assign('subCategory', $mysql -> row);
  3. ?>



ja bym zrobil cos takiego:
  1. <?php
  2. foreach ($mysql -> row as $Category)
  3. {
  4. $arr[] = $mysql -> row;
  5. }
  6. $smarty -> assign('subCategory', $arr);
  7. ?>
Lee
Zamiast rekordu pokazuje mi coś takiego
Cytat
1OAu


I z debugera
Cytat
Smarty Debug Console
included templates & config files (load time in seconds):
Blue/index.tpl (0.43306) (total)
Blue/modules.tpl (0.41237)
Blue/category.tpl (0.40429)
assigned template variables:
{$GetFile} category.php
{$SCRIPT_NAME} /lee/cms/category.php
{$admin_bg_1} url('templates/Blue/images/bg_01.gif')
{$category} Array (1)
0 => Array (5)
id => 1
name => Others
description => Artykuły o czymś tam
image => upload/category/avatar_002.jpg
main_category => empty
{$color_1} #010058
{$color_2} #0200BC
{$news_bg_1} url('templates/Blue/images/bg_01.gif')
{$news_bg_3} empty
{$subCategory} Array (1)
0 => Array (1)
0 => Array (5)
id => 1
name => Others
description => Artykuły o czymś tam
image => upload/category/avatar_002.jpg
main_category => empty
{$theme} Blue
assigned config file variables (outer template scope):
{#files#} Array (0)
{#vars#} Array (0)


Update: ok już sobie poradziłem, miałem literkówke było mysq = new MySQL a nie mysql...
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.