For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > August 2005 > Re: [SMARTY] looping through variable names









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [SMARTY] looping through variable names
Maximillian Schwanekamp

2005-08-17, 10:02 pm

Kathleen Krause-Thomson wrote:
> ...I need to
> loop through array variable names as if they were variable variables.
> How would I do this in Smarty?
> <p>Job Title: {$budget1.jobTitle}
> Percent of Full Time:{$budget1.percentFullTime}</p>
> Next section needs to be:...


From what you gave so far, it seems like you just need to assign your
array $budget, and use {foreach} to iterate over it. E.g.:
<?php
$budgets = array();
$budgets[] = array('jobTitle'=>'First Job', 'percentFullTime'=>100);
$budgets[] = array('jobTitle'=>'Second Job', 'percentFullTime'=>75);
//etc...
?>

{* smarty *}
{foreach from=$budgets item="budget"}
<p>Job Title: {$budget.jobTitle}
Percent of Full Time:{$budget.percentFullTime}</p>
{foreachelse}
<p>No budgets found.</p>
{/foreach}

If that doesn't answer the question, can you post your PHP, and [a
sample of] the array structure?

--
Max Schwanekamp
http://www.neptunewebworks.com/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com