|
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 |
muralik Smarty Rookie
Joined: 08 Mar 2004 Posts: 25
|
Posted: Thu Apr 01, 2004 3:36 am Post subject: table in columns from an associative array |
|
|
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 |
|
vijaynair Smarty n00b
Joined: 24 Mar 2004 Posts: 3 Location: Mumbai, India
|
Posted: Sat Apr 17, 2004 4:59 pm Post subject: |
|
|
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 |
|
vijaynair Smarty n00b
Joined: 24 Mar 2004 Posts: 3 Location: Mumbai, India
|
Posted: Sat Apr 17, 2004 5:00 pm Post subject: |
|
|
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 |
|
|
|
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
|