<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: pulling unique values from table into select in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/pulling-unique-values-from-table-into-select/m-p/38067#M3742</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/21482"&gt;@jpaullewer&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for selecting unique/distinct values of column from the table you need to call &lt;STRONG&gt;hubdb_table_column(######, 'state').options &lt;/STRONG&gt;it will fetch your required data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is your code with some modification to fetch unique or distnict value of state from the table.&lt;/P&gt;&lt;PRE&gt;&amp;lt;form id="form_id" method="get"&amp;gt;
    &amp;lt;select name="state" form="form_id" onChange="form1.submit()"&amp;gt;
        &amp;lt;option value="Select a State"&amp;gt;Select a State&amp;lt;/option&amp;gt;
        {% set stateValues = hubdb_table_column(######, 'state').options %}
        {% for row in stateValues %}
            {% if row.id == request.query_dict.state %}
                &amp;lt;option selected="selected" value="{{ row.id }}"&amp;gt;{{ row.name }}&amp;lt;/option&amp;gt;
            {% else %}
                &amp;lt;option value="{{ row.id }}"&amp;gt;{{ row.name }}&amp;lt;/option&amp;gt;
            {% endif %}
        {% endfor %}
    &amp;lt;/select&amp;gt;
&amp;lt;/form&amp;gt;&lt;/PRE&gt;&lt;P&gt;We hope it will work for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="UserSignature lia-message-signature"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;IMG src="https://cdn2.hubspot.net/hubfs/98485/2000px-Ok_sign_font_awesome.png" border="0" width="30" height="30" /&gt;&lt;/TD&gt;&lt;TD&gt;Did my post help answer your query? Help the Community by &lt;STRONG&gt;marking it as a solution&lt;/STRONG&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;STRONG&gt;TRooInbound Team&lt;/STRONG&gt;&lt;P&gt;more help please visit at &lt;A href="https://trooinbound.com/" target="_blank"&gt;www.trooinbound.com&lt;/A&gt; or email at &lt;A href="mailto:hello@trooinbound.com" target="_blank"&gt;hello@trooinbound.com&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 17 Nov 2017 06:54:59 GMT</pubDate>
    <dc:creator>TRooInbound</dc:creator>
    <dc:date>2017-11-17T06:54:59Z</dc:date>
    <item>
      <title>pulling unique values from table into select</title>
      <link>https://community.hubspot.com/t5/CMS-Development/pulling-unique-values-from-table-into-select/m-p/37973#M3734</link>
      <description>&lt;P&gt;I need to pull a set of unique values from a particular table column.&amp;nbsp; Specifically, I want to pull a distinct list of states and populate a select list.&amp;nbsp; I have the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;form id="form_id" method="get"&amp;gt;&lt;BR /&gt;&amp;lt;select name="state" form="form_id" onChange="form1.submit()"&amp;gt;&lt;BR /&gt;&amp;lt;option value="Select a State"&amp;gt;Select a State&amp;lt;/option&amp;gt;&lt;BR /&gt;{% set rows = hubdb_table_rows(######, '&amp;amp;orderBy=state') %}&lt;BR /&gt;{% set names = rows|map(attribute='state') %}&lt;BR /&gt;{% for row in names %}&lt;BR /&gt;{% if names == request.query_dict.state %}&lt;BR /&gt;&amp;lt;option selected="selected" value="{{ row }}"&amp;gt;{{ row }}&amp;lt;/option&amp;gt;&lt;BR /&gt;{% else %}&lt;BR /&gt;&amp;lt;option value="{{ row }}"&amp;gt;{{ row }}&amp;lt;/option&amp;gt;&lt;BR /&gt;{% endif %}&lt;BR /&gt;{% endfor %}&lt;BR /&gt;&amp;lt;/select&amp;gt;&lt;BR /&gt;&amp;lt;/form&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It does just as it should in pulling all of the states and ordering them in a select object on a form.&amp;nbsp; I could create a state table, however we don't have business in every state and I want to only pull states where we have business.&amp;nbsp; Is there a way to add "distinct" or "unique" to the hubdb_table_rows or possibly to the rows|map(attribute='state') syntax that will do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 18:21:53 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/pulling-unique-values-from-table-into-select/m-p/37973#M3734</guid>
      <dc:creator>jpaullewer</dc:creator>
      <dc:date>2017-11-16T18:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: pulling unique values from table into select</title>
      <link>https://community.hubspot.com/t5/CMS-Development/pulling-unique-values-from-table-into-select/m-p/38067#M3742</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/21482"&gt;@jpaullewer&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for selecting unique/distinct values of column from the table you need to call &lt;STRONG&gt;hubdb_table_column(######, 'state').options &lt;/STRONG&gt;it will fetch your required data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is your code with some modification to fetch unique or distnict value of state from the table.&lt;/P&gt;&lt;PRE&gt;&amp;lt;form id="form_id" method="get"&amp;gt;
    &amp;lt;select name="state" form="form_id" onChange="form1.submit()"&amp;gt;
        &amp;lt;option value="Select a State"&amp;gt;Select a State&amp;lt;/option&amp;gt;
        {% set stateValues = hubdb_table_column(######, 'state').options %}
        {% for row in stateValues %}
            {% if row.id == request.query_dict.state %}
                &amp;lt;option selected="selected" value="{{ row.id }}"&amp;gt;{{ row.name }}&amp;lt;/option&amp;gt;
            {% else %}
                &amp;lt;option value="{{ row.id }}"&amp;gt;{{ row.name }}&amp;lt;/option&amp;gt;
            {% endif %}
        {% endfor %}
    &amp;lt;/select&amp;gt;
&amp;lt;/form&amp;gt;&lt;/PRE&gt;&lt;P&gt;We hope it will work for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="UserSignature lia-message-signature"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;IMG src="https://cdn2.hubspot.net/hubfs/98485/2000px-Ok_sign_font_awesome.png" border="0" width="30" height="30" /&gt;&lt;/TD&gt;&lt;TD&gt;Did my post help answer your query? Help the Community by &lt;STRONG&gt;marking it as a solution&lt;/STRONG&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;STRONG&gt;TRooInbound Team&lt;/STRONG&gt;&lt;P&gt;more help please visit at &lt;A href="https://trooinbound.com/" target="_blank"&gt;www.trooinbound.com&lt;/A&gt; or email at &lt;A href="mailto:hello@trooinbound.com" target="_blank"&gt;hello@trooinbound.com&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 17 Nov 2017 06:54:59 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/pulling-unique-values-from-table-into-select/m-p/38067#M3742</guid>
      <dc:creator>TRooInbound</dc:creator>
      <dc:date>2017-11-17T06:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: pulling unique values from table into select</title>
      <link>https://community.hubspot.com/t5/CMS-Development/pulling-unique-values-from-table-into-select/m-p/38158#M3746</link>
      <description>&lt;P&gt;Thank you.&amp;nbsp; This solution only works if you set a column as a "select" type.&amp;nbsp; I was trying to do this as a regular text column.&amp;nbsp; I changed it to a select column and this solution does work.&amp;nbsp; Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 14:39:57 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/pulling-unique-values-from-table-into-select/m-p/38158#M3746</guid>
      <dc:creator>jpaullewer</dc:creator>
      <dc:date>2017-11-17T14:39:57Z</dc:date>
    </item>
  </channel>
</rss>

