PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.smarty.general > eval problem
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
eval problem

Réponse
 
LinkBack Outils de la discussion
Vieux 11/03/2006, 15h12   #1
Michael M
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut eval problem

Hi, I need your with the EVAL function.

In PHP I have a list of 27 fields, like this:

$advert['act1'] = 'foo';
$advert['act2'] = 'bar';
....
$advert['act26'] = 'doo';
$advert['act27'] = 'da';

I know this smells like it should be an array, but for
particular reasons it is not. So the template looks
like this:
{$advert.act1}<br>
{$advert.act2}<br>
....
{$advert.act26}<br>
{$advert.act27}<br>

Can I replace this with a loop? Something like:
{section name=foo start=1 loop=27}
{eval var="\$advert.act`$smarty.section.foo.index`"}
<br>
{/section}

The code above does not work, by the way. The line
{eval var="\$advert.act`$smarty.section.foo.index`"}
produces:
$advert.act1

If I add braces:
{eval var="{\$advert.act`$smarty.section.foo.index`}"}
it displays:
{\.act1"}

So I must be missing something here.

Thanks,
Mike

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
  Réponse avec citation
Vieux 11/03/2006, 15h27   #2
Alain Williams
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] eval problem

On Sat, Mar 11, 2006 at 07:12:18AM -0800, Michael M wrote:
> Hi, I need your with the EVAL function.
>
> In PHP I have a list of 27 fields, like this:
>
> $advert['act1'] = 'foo';
> $advert['act2'] = 'bar';
> ...
> $advert['act26'] = 'doo';
> $advert['act27'] = 'da';
>
> I know this smells like it should be an array, but for
> particular reasons it is not. So the template looks
> like this:
> {$advert.act1}<br>
> {$advert.act2}<br>
> ...
> {$advert.act26}<br>
> {$advert.act27}<br>
>
> Can I replace this with a loop? Something like:
> {section name=foo start=1 loop=27}
> {eval var="\$advert.act`$smarty.section.foo.index`"}
> <br>
> {/section}


What is wrong with:
{foreach from=$advert item=ad }
{$ad}<br>
{/foreach}

> The code above does not work, by the way. The line
> {eval var="\$advert.act`$smarty.section.foo.index`"}
> produces:
> $advert.act1
>
> If I add braces:
> {eval var="{\$advert.act`$smarty.section.foo.index`}"}
> it displays:
> {\.act1"}
>
> So I must be missing something here.
>
> Thanks,
> Mike
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


--
Alain Williams
Parliament Hill Computers Ltd.
Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256 http://www.phcomp.co.uk/

#include <std_disclaimer.h>
  Réponse avec citation
Vieux 11/03/2006, 15h31   #3
Michael M
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] eval problem

Hi Alain,

A bit more background: The associative PHP array is
actually the representation of a database row. As
such, it has many other fields besides act1, act2 etc.

Thats why I can't use the foreach loop.

Thanks,
Mike.

--- Alain Williams <addw@phcomp.co.uk> wrote:

> On Sat, Mar 11, 2006 at 07:12:18AM -0800, Michael M
> wrote:
> > Hi, I need your with the EVAL function.
> >
> > In PHP I have a list of 27 fields, like this:
> >
> > $advert['act1'] = 'foo';
> > $advert['act2'] = 'bar';
> > ...
> > $advert['act26'] = 'doo';
> > $advert['act27'] = 'da';
> >
> > I know this smells like it should be an array, but

> for
> > particular reasons it is not. So the template

> looks
> > like this:
> > {$advert.act1}<br>
> > {$advert.act2}<br>
> > ...
> > {$advert.act26}<br>
> > {$advert.act27}<br>
> >
> > Can I replace this with a loop? Something like:
> > {section name=foo start=1 loop=27}
> > {eval

> var="\$advert.act`$smarty.section.foo.index`"}
> > <br>
> > {/section}

>
> What is wrong with:
> {foreach from=$advert item=ad }
> {$ad}<br>
> {/foreach}
>
> > The code above does not work, by the way. The line
> > {eval

> var="\$advert.act`$smarty.section.foo.index`"}
> > produces:
> > $advert.act1
> >
> > If I add braces:
> > {eval

> var="{\$advert.act`$smarty.section.foo.index`}"}
> > it displays:
> > {\.act1"}
> >
> > So I must be missing something here.
> >
> > Thanks,
> > Mike
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam

> protection around
> > http://mail.yahoo.com
> >
> > --
> > Smarty General Mailing List

> (http://smarty.php.net/)
> > To unsubscribe, visit:

> http://www.php.net/unsub.php
> >

>
> --
> Alain Williams
> Parliament Hill Computers Ltd.
> Linux Consultant - Mail systems, Web sites,
> Networking, Programmer, IT Lecturer.
> +44 (0) 787 668 0256 http://www.phcomp.co.uk/
>
> #include <std_disclaimer.h>
>



__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
  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 12h55.


Édité par : vBulletin® version 3.7.2
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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,21149 seconds with 11 queries