Reply to Re: smarty using index to get the value in array

Your name:

Reply:


Posted by badar.waqas@gmail.com on 11/13/07 09:36

On Nov 13, 3:06 am, "sksksk" <dkfjld...@dfd.com> wrote:
> I want to achieve the following process in the smarty
> for $item['menu' . $i] one i should be able to get the value using
> loop.index, but
> without any luck.
>
> any help is appreciated.
>
> <?php for ($i = 1; $i <= 30; $i++) : ?>
> <tr>
> <th><?= $i ?></th>
> <td><input type="text" class="text1" name="menu<?= $i ?>"
> value="<?= $item['menu' . $i] ?>"/></td>
> <td><input type="text" class="price" name="menu<?= $i ?>_price"
> value="<?= $item['menu' . $i . '_price'] ?>"/></td>
> </tr>
> <?php endfor; ?>
>
> ====SMARTY====
> {section name=loop start=1 loop=30}
> <tr>
> <td>{$smarty.section.loop.index}</td>
> {assign var="i" value=$smarty.section.loop.index}
> <td><input type="text" class="text1" name="menu{$i}"
> value="{$item}{'menu$i}"/></td>
> </tr>
> {/section}

I think this will work

{section name=loop start=1 loop=30}
<tr>
<td>{$smarty.section.loop.index}</td>
{assign var="i" value=$smarty.section.loop.index}
{assign var="arrayIndex" value="menu".
$smarty.section.loop.index."_price"}
<td><input type="text" class="text1" name="menu{$i}"
value="{$item.$arrayIndex}"/></td>
</tr>
{/section}

Store array index in variable and then access it.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация