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.

List channel field entries without duplication

May 19, 2012 11:01am

Subscribe [3]
  • #1 / May 19, 2012 11:01am

    niallthompson

    17 posts

    Hello,
    I am trying to list a series of channel field entries but without duplication. I am trying to list a series of locations.

    Here is my code which works but results in duplications:

    {site_name} have property, houses and flats to rent in {exp:channel:entries channel="lettings|sales" status="open" backspace="1" orderby="town" sort="asc" dynamic="no"}<a href="/properties/search_results/search&town={town}&category=/">{town}</a>, {/exp:channel:entries} in London, UK.

    Any ideas?

  • #2 / May 19, 2012 10:56pm

    mark186282

    290 posts

    Probably easiest to roll it with the query module:

    assuming:
    field_id_1 = town

    (not tested, just wrote off the top of my head…)

    {exp:query
    backspace="2"
    sql=" SELECT
       exp_channel_data.field_id_1 as town
      FROM
       exp_channel_data,
       exp_channel_titles,
       exp_channels
      WHERE
       exp_channels.channel_name IN ('lettings', 'sales')
       AND
       exp_channels.channel_id = exp_channel_titles.channel_id
       AND
       exp_channel_titles.entry_id = exp_channel_data.entry_id
       AND
       exp_channel_titles.status != 'closed'
       AND
       exp_channel_data.field_id_1 != ''
      GROUP BY
       exp_channel_data.field_id_1"}<a href="/properties/search_results/search&town={town}&category=/">{town}</a>, {/exp:query}

    This should give you a unique list of all towns

     

  • #3 / May 21, 2012 1:04pm

    Shane Eckert

    7174 posts

    Hey niallthompson,

    Thank you for posting your question here on the ExpressionEngine forums.

    Does Mark’s solution look like a viable option?

    Please let us know!

    Cheers,

  • #4 / May 21, 2012 2:50pm

    niallthompson

    17 posts

    Works perfectly!

    Thank you.

    But now I am also trying to combine the postcode1 field also.

    At the moment getting a SQL error probably to do with the GROUP BY.

    Appreciate any further help…

    {exp:query
         backspace="1"
         sql=" SELECT
            exp_channel_data.field_id_4 as postcode1
           AND
            exp_channel_data.field_id_3 as town 
           FROM
            exp_channel_data,
            exp_channel_titles,
            exp_channels
           WHERE
            exp_channels.channel_name IN ('lettings', 'sales')
            AND
            exp_channels.channel_id = exp_channel_titles.channel_id
            AND
            exp_channel_titles.entry_id = exp_channel_data.entry_id
            AND
            exp_channel_titles.status != 'closed'
            AND
            exp_channel_data.field_id_4 != ''
            AND
            exp_channel_data.field_id_3 != ''
           GROUP BY
            exp_channel_data.field_id_4"}"{postcode1}",{town}{/exp:query}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases