Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

associative array index in a variable

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
bsmith
Smarty Rookie


Joined: 29 May 2003
Posts: 11

PostPosted: Wed Jul 02, 2003 4:51 pm    Post subject: associative array index in a variable Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 02, 2003 4:57 pm    Post subject: Re: associative array index in a variable Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Jul 02, 2003 5:31 pm    Post subject: Re: associative array index in a variable Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
bsmith
Smarty Rookie


Joined: 29 May 2003
Posts: 11

PostPosted: Wed Jul 02, 2003 5:44 pm    Post subject: thanks to all, I came up with a way Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General 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