Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

freaking out on templates : multidimensional array with asso

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
drgonzo120
Smarty n00b


Joined: 07 Jan 2005
Posts: 2

PostPosted: Fri Jan 07, 2005 2:03 am    Post subject: freaking out on templates : multidimensional array with asso Reply with quote

hello; i'm trying to show links on a page, ordered per category

database:

category 1 ------*link

since i haven't quite figured out how to fille that array, i came to the idea of creating a test array (the links schould have descriptions & locations too, i know, just an example, now i see instead of url there should haven been name there, but that doesnt matter because it is an example)

(do we have to use ONE array ? but then again, with two arrays i wouldn't know how to connect them, i'm not good in arrays)

it looks like this (don't get scared)
Quote:

$smarty->assign("all", array("catname"=>"art",array(
array("url"=>"escher"),
array("url"=>"comcom"),
array("url"=>"dali") ) ),

array("catname"=>"music",array(
array("url"=>"infected"),
array("url"=>"astral projection"),
array("url"=>"hallucinogen")
)),
array("catname"=>"labels",array(
array("url"=>"kairoo"),
array("url"=>"phonokol")
))
);

now, the debug says this:

Quote:

Array (2)
catname => art
0 => Array (3)
0 => Array (1)
url => escher
1 => Array (1)
url => comcom
2 => Array (1)
url => dali


very basic tpl:


Quote:

{section name=sec1 loop=$all}
<ul>
<li> {$all[sec1].catname }</li>
</ul>
{/section}



but how do i call a categoryname (art, labels, music) link & a link ? but when is finished this all,

i started cursing because i think you can't do this with one loop ? (because of the one to many relationship ?)

it's been a long time since i programmed again


i want it to look like this (i already have a script , but it's without templates, and i want to learn the templates)




anyway, is my array structure ok ?

(yeah, should have started with showing the dj's , but that was easy)


thanks

[/img]
Back to top
View user's profile Send private message
drgonzo120
Smarty n00b


Joined: 07 Jan 2005
Posts: 2

PostPosted: Fri Jan 07, 2005 2:12 am    Post subject: Reply with quote

can't i do it this way :
Quote:

$smarty->assign("all",
array("catname"=>"art", array("url"=>"escher"),array("url"=>"comcom"),array("url"=>"dali") ) ,
array("catname"=>"music",array("url"=>"infected"),array("url"=>"astral projection"),array("url"=>"hallucinogen")),
array("catname"=>"labels",array("url"=>"kairoo"),array("url"=>"phonokol"))
);
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP