[TriLUG] Smarty

Brian Henning bhenning at pineinst.com
Thu Sep 19 14:52:34 EDT 2013


Maybe I'm being dense, but if you only care about the first record, why do a
foreach at all?  Is that the only way that Smarty lets you get at the
records in the result set?

~B

-----Original Message-----
From: trilug-bounces at trilug.org [mailto:trilug-bounces at trilug.org] On Behalf
Of Brian McCullough
Sent: Thursday, September 19, 2013 2:25 PM
To: Triangle Linux Users Group General Discussion
Subject: Re: [TriLUG] Smarty

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

-- 
This message was sent to: Brian <bhenning at pineinst.com>
To unsubscribe, send a blank message to trilug-leave at trilug.org from that
address.
TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
Unsubscribe or edit options on the web	:
http://www.trilug.org/mailman/options/trilug/bhenning%40pineinst.com
Welcome to TriLUG: http://trilug.org/welcome




More information about the TriLUG mailing list