2

I'm trying to create a dropdown of matrix field data using the search form. It's outputting the matrix data, but I can't seem to figure out how to remove duplicate content. Say I'm using the data "john doe" on multiple entries -- it's showing for every entry, not just once. Is there any way to fix this? Thanks in advance.

{exp:low_search:form query="{segment_3}"}   
    <label>Arranger:</label>
    <select name="search:tags:arranger">
        {exp:channel:entries channel="products" dynamic="no"}
            {tags}<option value="{arranger}">{arranger}</option>{/tags}
        {/exp:channel:entries}
    </select>
    <button type="submit">Search</button>
{/exp:low_search:form}
1

You'll need to use the Query module for this. Something like

{exp:query sql="SELECT DISTINCT col_id_X AS val FROM exp_matrix_data WHERE field_id = Y ORDER BY val"}
  <option>{val}</option>
{/exp:query}

...where you need to replace X with the correct column ID and Y with the correct field ID.

EDIT Alternatively, you can try this query:

{exp:query sql="SELECT col_id_X AS val FROM exp_matrix_data WHERE field_id = Y AND col_id_X != '' GROUP BY col_id_X ORDER BY val"}
  <option>{val}</option>
{/exp:query}
| improve this answer | |
  • Thanks, Low! I'm still getting an error though. The column is 'arranger' and the field is 'tags'. Here is the error: Error Number: 1054 Unknown column 'arranger' in 'field list' SELECT DISTINCT arranger AS val FROM exp_matrix_data WHERE field_id = tags ORDER BY val Filename: modules/query/mod.query.php Line Number: 53 – Lisa Ellington Mar 4 '15 at 21:02
  • You need the numeric IDs here. Not the short-names. So, for example, col_id_5 and field_id = 8 if those IDs are 5 and 8. Go to the Matrix' field settings. There you can see the field_id in the URL. To get to the col_id, view the page source and look for it. – Low Mar 4 '15 at 21:08
  • ...or look up the IDs using the SQL Manager: browse the exp_channel_fields and exp_matrix_cols tables. – Low Mar 4 '15 at 21:15
  • Got em, but still having an issue. It's showing the items 4 times. Here's the code: {exp:query sql="SELECT DISTINCT col_id_25 AS val FROM exp_matrix_data WHERE field_id = 117 ORDER BY val"} <option>{val}</option> {/exp:query} – Lisa Ellington Mar 4 '15 at 21:16
  • Try the second query I just added. Also, make sure the values are indeed the same (no trailing spaces etc). – Low Mar 4 '15 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.