Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Smarty] Pokazuje co nie trzeba
Lee
post
Post #1





Grupa: Zarejestrowani
Postów: 319
Pomógł: 0
Dołączył: 11.04.2006
Skąd: Chojnów

Ostrzeżenie: (0%)
-----


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


--------------------
Nie pomagam w sprawach php na GG i PW od tego jest forum!
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
Skobi
post
Post #2





Grupa: Zarejestrowani
Postów: 174
Pomógł: 1
Dołączył: 19.02.2004

Ostrzeżenie: (10%)
X----


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. ?>
Go to the top of the page
+Quote Post
Lee
post
Post #3





Grupa: Zarejestrowani
Postów: 319
Pomógł: 0
Dołączył: 11.04.2006
Skąd: Chojnów

Ostrzeżenie: (0%)
-----


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...

Ten post edytował Lee 12.10.2006, 21:00:18


--------------------
Nie pomagam w sprawach php na GG i PW od tego jest forum!
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 04:16