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.

Don't want multiple entries in a dynamic menu

August 14, 2012 2:28am

Subscribe [2]
  • #1 / Aug 14, 2012 2:28am

    Magnusvb

    57 posts

    Hello
    In a simple search form I have this code:

    {exp:search:simple_form channel="my_school" status="open" search_in="everywhere" where="exact" result_page="my_school/resultat"}
       <select name="keywords">
          <option value="" selected="selected">- Select city -</option>
            {exp:channel:entries channel="my_school" }
     <option value="{school_city}">{school_city}</option>  
    {/exp:channel:entries}

    The select menu is created dynamically from the custom field “school_city” for each entries. Problem: If there are, for example, 3 different schools entries for city New York - the word “New York” is displayed 3 times in the menu (just want it to be displayed 1 time).

    Is it possible to solve? Or do I need to use Categories?

    I would like to not to have to use Categories because this is a work “in progress”. Each city have schools added over time - and I don’t want a city to show up in the drop menu before it have at least one school added. In the end it will be around 300 cities.

    Best regards,
    Magnus

  • #2 / Aug 14, 2012 12:50pm

    Ralph

    78 posts

    I’m not sure there’s a way to do that with the channel entries tag. But you could use the Query tag. First you’ll need to know the field id which you can find out in Admin > Channel Admin > Channel Fields. Click your field group and then the field and look at the URL, it should have &field;_id= in there which will tell you your field_id. Then you can use mysql to select that distinct field as follows. This assumes your field_id is 8 (look for field_id_8), you will need to change it to what yours is:

    {exp:query sql="SELECT DISTINCT `field_id_8` AS school_city FROM `exp_channel_data` WHERE `field_id_8`<>'' ORDER BY `field_id_8`"}
     <option value="{school_city}">{school_city}</option>
    {/exp:query}
  • #3 / Aug 15, 2012 2:34am

    Magnusvb

    57 posts

    Many thanks!
    Worked great 😊

    (Had another issue (not related) - will take that in another thread)

    Cheers, Magnus

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

ExpressionEngine News!

#eecms, #events, #releases