|
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 |
bsmith Smarty Rookie
Joined: 29 May 2003 Posts: 11
|
Posted: Wed Jul 02, 2003 4:51 pm Post subject: associative array index in a variable |
|
|
Hello, I'm looping through a set of data, and i need to periodically spit out a subtotal of one of my columns. I'm doing to total calc in php for speed and storing the totals in a separate array, using another column from my dataset as the array index.
So, my subtotals would be $totals = array( user_id => total )
The user id is held in my dataset, "units", so it looks like {$units.user_id?}, but smarty will not let me do {$totals.$units.user_id}
Any ideas? I would rather not use math functions in smarty if I can help it.
Brian |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 02, 2003 4:57 pm Post subject: Re: associative array index in a variable |
|
|
bsmith wrote: | smarty will not let me do {$totals.$units.user_id} |
Hi Brian. There is a thread on this topic here on the forums (concerning array syntax), but I am sorry that I can not look for it for you right now. Here's an idea:
{assign var=totals_units value=$totals.$units}
{$totals_units.user_id}
greets |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Jul 02, 2003 5:31 pm Post subject: Re: associative array index in a variable |
|
|
boots wrote: | Code: |
{assign var=totals_units value=$totals.$units}
{$totals_units.user_id}
|
|
@boots: this is the precedence that smarty does implicetly, if i see it right. the other precedence would need a workaround.
Code: |
{assign var=units_user_id value=$units.$user_id}
{$totals.$units_user_id}
|
it's been quite some hours at the keyboard for me now, i maybe wrong. |
|
Back to top |
|
bsmith Smarty Rookie
Joined: 29 May 2003 Posts: 11
|
Posted: Wed Jul 02, 2003 5:44 pm Post subject: thanks to all, I came up with a way |
|
|
I modified the format of my dataset, created an array of arrays in php first, and an nested foreach in smarty did the trick.
Thanks,
Brian |
|
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
|