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

table in columns from an associative array

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
muralik
Smarty Rookie


Joined: 08 Mar 2004
Posts: 25

PostPosted: Thu Apr 01, 2004 3:36 am    Post subject: table in columns from an associative array Reply with quote

I have an array like this, i need to display it in specified columns in a table, how do i do this ???

for example
each cell should look like
Code:

<img src="$RandomImage"><a href="index.php?{$CategoryID}>$Category</a>


Array
Code:

Array
(
    [0] => Array
        (
            [CategoryID] => 1
            [Category] => Animation
            [Keywords] => Animation/
            [RandomImage] => 1/cruise.jpg
        )

    [1] => Array
        (
            [CategoryID] => 1
            [Category] => Animation
            [Keywords] => Animation/
            [RandomImage] => 1/ctree.jpg
        )

    [2] => Array
        (
            [CategoryID] => 1
            [Category] => Animation
            [Keywords] => Animation/
            [RandomImage] => 1/mod_177_1.jpg
        )

    [3] => Array
        (
            [CategoryID] => 1
            [Category] => Animation
            [Keywords] => Animation/
            [RandomImage] => 1/mod_225_1.jpg
        )

    [4] => Array
        (
            [CategoryID] => 1
            [Category] => Animation
            [Keywords] => Animation/
            [RandomImage] => 1/mod_252_4.jpg
        )

)




can anyone help me? how to display in columns ??
Back to top
View user's profile Send private message
vijaynair
Smarty n00b


Joined: 24 Mar 2004
Posts: 3
Location: Mumbai, India

PostPosted: Sat Apr 17, 2004 4:59 pm    Post subject: Reply with quote

Try following.

Assign the array in PHP as

catgList['1']->categoryID = '1';
catgList['1']->category = 'something1';
catgList['1']->Keywords = 'keywords1';
catgList['1']->pictureID = 'jpg file name 1';
....
Repeat this definition for the full array.

Assign this array to smarty object.

$smarty->assign("catgList",$catgList);

Now in the tpl file

{ foreach from=$catgList key=key value=disp }

<img src="{$disp->pictureID}"><a href="index.php?{$disp->CategoryID}>{$disp->Category}</a>

{/foreach}

This is working for me very well.

Hope this helpsyou.

ALl the best.

Vijay Nair
_________________
Vijayakumar Nair
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
vijaynair
Smarty n00b


Joined: 24 Mar 2004
Posts: 3
Location: Mumbai, India

PostPosted: Sat Apr 17, 2004 5:00 pm    Post subject: Reply with quote

Hello,

Small correction in the earlier post.

instead of value=disp, you should use item=disp.

Sorry for the mixup.

Vijay
_________________
Vijayakumar Nair
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins 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