[TriLUG] Smarty

Brian McCullough bdmc at bdmcc-us.com
Thu Sep 19 14:25:13 EDT 2013


On Thu, Sep 19, 2013 at 01:54:48PM -0400, Kevin Hunter Kesling wrote:
> At 1:37pm -0400 Thu, 19 Sep 2013, Brian McCullough wrote:
> >On Thu, Sep 19, 2013 at 01:24:12PM -0400, Brian Henning wrote:
> >>Can you not limit your database read (i.e. a carefully-crafted
> >>WHERE or LIMIT in sql parlance) instead of limiting the iteration
> >>afterwards?
> >
> >I could probably do that. I was trying to re-use an existing
> >function call that returns a set of data that would have been useful
> >in this case, instead of creating something new.

Hi Kevin,

Not quoting much, but carrying on -- yes, the existing SQL statement
does limit the result set considerably, I think that the maximum is
probably about a dozen records.

However, in this particular case, I just want the first one, so I was
going to do a break.


However, it seems that Smarty does provide a couple of ways around this
problem, although, for this, it isn't very elegant, as others have
mentioned.

They have "First," "Last" and a couple of other "state" variables,
where they are True if the condition is set.

So what I wound up doing was:

Foreach stuff
  If First
    Process my data
  Fi
End


The Foreach still processes the whole array, just doesn't do anything
with the data.


Thank you all,
Brian



More information about the TriLUG mailing list