ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Possible to not display repeating data?

August 20, 2007 10:37pm

Subscribe [4]
  • #1 / Aug 20, 2007 10:37pm

    Imagine you have a weblog that has the custom field “eye_color.”  To get a list of all the colors submitted you would use the code:

    {exp:weblog:entries weblog="xxxxx"}
    {eye_color}
    
    {/exp:weblog:entries}

    With the above code, you are bound to get a list with several entries for brown, blue, green, etc.

    Is there a way to code this so that each color only appears once in the list?  In other words, no identical data is repeated.

  • #2 / Aug 20, 2007 10:47pm

    Sue Crocker

    26054 posts

    The easiest way to do this is with a query. You’d need to know which field contains eye_color and use that as a part of your query.

    Something like this:

    {exp:query sql="SELECT DISTINCT(field_id_4) as eye_color from exp_weblog_data where weblog_id='1'"}
    {eye_color}
    
    {/exp:query}
  • #3 / Aug 20, 2007 10:55pm

    Lisa Wess

    20502 posts

    You might also look for Sortee - it’s a plugin by Mr. Wilson that can help with this.

  • #4 / Aug 20, 2007 10:57pm

    Sue Crocker

    26054 posts

    I’d forgotten about Sortee. Thanks for the reminder!

  • #5 / Sep 11, 2007 1:51pm

    Mr. Wilson

    131 posts

    Your code to do that using Sortee would look something like:

    {exp:sortee}
    {sortee:heading1}<h1>{heading}</h1>{/sortee:heading1}
    {exp:weblog:entries weblog="the_eyes_have_it"}
    {sortee:item}
    {sortee:criterion}{eye_color}{/sortee:criterion}
    {sortee:criterion}{name}{/sortee:criterion}
    {name}'s eyes are {eye_color}
    
    {/sortee:item}
    {/exp:weblog:entries}
    {/exp:sortee}

    ...which will give you something like:

    <h1>Blue</h1>
    Alice's eyes are Blue
    
    Andrea's eyes are Blue
    
    Zeus's eyes are Blue
    
    
    <h1>Green</h1>
    Henry's eyes are Green
    
    Ian's eyes are Green
    
    Lou's eyes are Green
    
    
    <h1>Red</h1>
    Opal's eyes are Red
    
    Paul's eyes are Red
    

    Hope that helps!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases