|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Caged Smarty Rookie
Joined: 27 Jan 2004 Posts: 5
|
Posted: Tue Jan 27, 2004 5:54 pm Post subject: Categories and Sub Cats |
|
|
I've been browsing the forums a few days and i've seen a few topics on this, I tried to implement the logic of others , but I still can't seem to peg this one.
I have the results returned from my cats and sub cats, but I can't figure out the proper way to return them to the template.
My array is as follows:
[php:1:e059e45873]
{$PARENT} Array (5)
0 => stdClass Object (4)
id => 2
name => Photoshop
parent => 0
num_articles => 0
1 => stdClass Object (4)
id => 4
name => Php
parent => 0
num_articles => 0
2 => stdClass Object (4)
id => 5
name => Flash
parent => 0
num_articles => 0
3 => stdClass Object (4)
id => 12
name => Cinema 4D
parent => 0
num_articles => 0
4 => stdClass Object (4)
id => 13
name => Xhtml and CSS
parent => 0
num_articles => 0
{$SUBS} Array (3)
0 => Array (3)
0 => stdClass Object (3)
id => 3
name => Interfaces and Web Design
num_articles => 0
1 => stdClass Object (3)
id => 6
name => Text
num_articles => 0
2 => stdClass Object (3)
id => 7
name => Misc
num_articles => 0
1 => Array (2)
0 => stdClass Object (3)
id => 9
name => OOP
num_articles => 0
1 => stdClass Object (3)
id => 14
name => Basic
num_articles => 0
2 => Array (3)
0 => stdClass Object (3)
id => 8
name => Basic Actionscript
num_articles => 0
1 => stdClass Object (3)
id => 10
name => Text Effects
num_articles => 0
2 => stdClass Object (3)
id => 11
name => Xml and Flash
num_articles => 0
[/php:1:e059e45873]
I get the above results using:
[php:1:e059e45873]
<?PHP
$cats = $db->get_results("SELECT id, name, parent, num_articles
FROM " . PREFIX . CAT_TABLE . "
WHERE parent = 0");
$smarty->assign('PARENT',$cats);
foreach($cats as $cat){
$subcats = $db->get_results("SELECT id, name, num_articles
FROM " . PREFIX . CAT_TABLE . "
WHERE parent ='" . $cat->id . "'");
$smarty->append('SUBS', $subcats);
}
?>
[/php:1:e059e45873]
The contents of my template is:
Code: |
<table style="width:400px;">
<tr><th>Categories</th></tr>
{foreach from=$PARENT item=parent_cat}
<tr class="rowdark"><td>{$parent_cat->name}</td></tr>
{foreach from=$SUBS item=sub}
<tr class="rowlight"><td>{$sub->name}</td></tr>
{/foreach}
{/foreach}
</table>
|
I assume this is wrong considering it doesn't work, whats the proper way to deal with this?
- Thanks in advance _________________ Purephotoshop.com - Tutorials and Resources
Purephotoshop.net - Forums and Community |
|
Back to top |
|
Caged Smarty Rookie
Joined: 27 Jan 2004 Posts: 5
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|