We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Loop-based conditional?

How Do I?

Kurt Deutscher's avatar
Kurt Deutscher
827 posts
9 years ago
Kurt Deutscher's avatar Kurt Deutscher

At the moment, I can’t seem to think up how to do this.

We have a channel tag that’s creating a list of zip/postal codes for 150 locations. Each entry is a different location.

Since some of the entries/locations are in the same zip code, I would like to remove any of the redundancies from the list.

I got this far: orderby=”loc_postal_code” sort=”asc”

So I’m thinking there must be some way for the current loop to compare it’s results with the previous loop and then only display if it’s data is different.

Anyone already had enough coffee and sleep to help me get started down the right path with this one?

Thanks.

       
Ingmar Greil's avatar
Ingmar Greil
29,243 posts
9 years ago
Ingmar Greil's avatar Ingmar Greil

Some PHP, probably: write zip code to a variable, compare with previous_zip, output variable if not equal, copy variable to previous_zip, rinse, repeat. Something like that, anyway. Possibly requires some tinkering with PHP parsing stages.

       
deswork's avatar
deswork
93 posts
9 years ago
deswork's avatar deswork

You may have to use the Query module https://docs.expressionengine.com/latest/add-ons/query/index.html

and write an SQL statement to get the distinct results

http://expressionengine.stackexchange.com/questions/11044/only-show-distinct-entries

       
Kurt Deutscher's avatar
Kurt Deutscher
827 posts
9 years ago
Kurt Deutscher's avatar Kurt Deutscher

Thank you both. I was hoping EE’s channel tag might have some new magic for this that I hadn’t noticed in the docs, but you did get me headed in the right direction.

And for anyone else that could make good use of this:

{exp:query sql="SELECT DISTINCT field_id_#### AS field_name FROM exp_channel_data WHERE channel_id=#### ORDER BY field_name ASC"}

{field_name}

{/exp:query}
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.