PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > smarty using index to get the value in array
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
smarty using index to get the value in array

Réponse
 
LinkBack Outils de la discussion
Vieux 12/11/2007, 23h06   #1
sksksk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut smarty using index to get the value in array

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 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}

  Réponse avec citation
Vieux 13/11/2007, 10h36   #2
badar.waqas@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: smarty using index to get the value in array

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 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.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h46.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09677 seconds with 10 queries