# Dynamic Comparison Table

**URL:** <https://community.hubspot.com/t/dynamic-comparison-table/44201>\
**Category:** CMS Development\
**Tags:** hubdb\
**Created:** [September 22, 2021, 10:24am UTC](https://community.hubspot.com/t/dynamic-comparison-table/44201 "2021-09-22T10:24:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [September 22, 2021, 10:24am UTC](https://community.hubspot.com/t/dynamic-comparison-table/44201/1 "2021-09-22T10:24:02Z")

</div>

Has anyone ever created a dynamic comparison table similar to Apples?

> **[iPhone - Compare Models](https://www.apple.com/uk/iphone/compare/?modelList=iphone8plus,iphone11promax,iphone13)**
>
> Compare features and technical specifications for iPhone 17 Pro, iPhone 17 Pro Max, iPhone Air, iPhone 17, iPhone 17e and many more.

I’ve tried using the below code, cloning it and tweaking each one by changing any key point from 1 to 2, 3 etc (i.e. showing 3 lists), but I can’t get it to work.

Similar to Apples, at the end of the URL my test page updates with the query for example **?house\_type=16** but unlike Apple, I’m unable to figure out how to add to this with the other lists.

Any ideas?

```lia-code-sample
<table class="filter_container"><!-- Table 1 -->
 <tr>
 <td>
 <!-- Filter -->
 <form id="filter1" method="get">
 <select name="house_type" form="filter1" onChange="this.form.submit()">
 <option value="show-all">Show All</option>
 {% set house_types1 = hubdb_table_column(1234567, "house_type").options %}
 {% for choice1 in house_types1 %}
 {% set house_type_list1 = house_type_list1~choice1.id|list %} 
 {% if choice1.id == request.query_dict.house_type %}
 <option selected="selected" value="{{ choice1.id }}">{{ choice1.name }}</option>
 {% else %}
 <option value="{{ choice1.id }}">{{ choice1.name }}</option>
 {% endif %}
 {% endfor %}
 </select>
 </form>
 <!-- Query Parameters -->
 {% set queryparam1 = "" %}
 {% if request.query_dict.house_type in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28"] %}
 {% set queryparam1 = queryparam1 ~ "house_type="~request.query_dict.house_type|urlencode %}
 {% endif %}
 {% if request.query_dict.house_type == "show-all" %}
 {% set queryparam1 = queryparam1 ~ "&orderBy=house_type" %}
 {% endif %}
 {% set table1 = hubdb_table_rows(1234567, queryparam1) %}
 {% if table1 == [] %}
 <p class='align-center'>Sorry, no listings found for that Search. Try changing your filter and search again.</p>
 {% else %} 
 {% for row in table1 %} 
 <div class="sitename">
 House Name: {{ row["house_type"].name}} <br>
 Ref: {{ row["house_type_ref"]}}
 </div>
 {% endfor %} 
 {% endif %} 
 </td>
 </tr>
 </table>

```

---

<div class="post-metadata">

**Author:** ![natsumimori](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/natsumimori/32/39807_2.png) [@natsumimori](https://community.hubspot.com/u/natsumimori)\
**Post date:** [September 23, 2021, 7:08am UTC](https://community.hubspot.com/t/dynamic-comparison-table/44201/2 "2021-09-23T07:08:37Z")

</div>

Thank you for your post @ben-duchy !

@Teun & @Sjardo Do you have experience with dynamic comparison table? Would you be able to weigh in here?

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [September 23, 2021, 7:20am UTC](https://community.hubspot.com/t/dynamic-comparison-table/44201/3 "2021-09-23T07:20:03Z")

</div>

Hi @ben-duchy and @natsumimori ,

The [hubdb\_table\_rows](https://developers.hubspot.com/docs/cms/hubl/functions#hubdb-table-rows) function uses the same query options as the [API](https://legacydocs.hubspot.com/docs/methods/hubdb/v2/get_table_rows).

If you want to pass multiple results, you should switch your column type to ‘multi-select’ and pass it all the values you need. It is not really efficient when you create new house types, but this should work.

Each row would have a option set from the multi-select, which would be in your case the numbers 1 to 28.  
Because you want the URL params to be comma separated, you do not have to do any formatting and could change your query to this:

`"house_type__in="~request.query_dict.house_type|urlencode`

Which should result in something like this:

`house_type__in=1%2C8%2C16%2C27`

Where %2C is the encoded ,  
Give it a try and let me know if this works 🙂

---

<div class="post-metadata">

**Author:** ![Indra](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/indra/32/98381_2.png) [@Indra](https://community.hubspot.com/u/Indra)\
**Post date:** [September 23, 2021, 9:37am UTC](https://community.hubspot.com/t/dynamic-comparison-table/44201/4 "2021-09-23T09:37:35Z")

</div>

Hi @ben-duchy,

What @Teun is telling is true. But to switch from the query within the url when having multiple values for one `query_dict`, you can use this code:

```lia-code-sample
{# Get query_dict #}
{% set cat_field = 'house_type' %}

{# if there is a paramater/filter selected #}
{% if request.query_dict != '' %}
 {% set dict = [] %} {# create array to collect categories #}
 {% for item in request.query|split('&') %} {# split paramaters together with values #}
 {% set currect_dict = item|split('=') %} {# split value from paramater #}
 {% if currect_dict[0] == cat_field %} {# check if it's a cat #}
 {% do dict.append(currect_dict[1]) %} {# add to selected cat array #} 
 {% endif %}
 {% endfor %}
{% endif %}

```

---

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [September 23, 2021, 4:28pm UTC](https://community.hubspot.com/t/dynamic-comparison-table/44201/5 "2021-09-23T16:28:32Z")

</div>

Thanks for your help. @Indra & @Teun, I will certainly give it a try. 👍

---

<div class="post-metadata">

**Author:** ![natsumimori](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/natsumimori/32/39807_2.png) [@natsumimori](https://community.hubspot.com/u/natsumimori)\
**Post date:** [September 24, 2021, 4:13am UTC](https://community.hubspot.com/t/dynamic-comparison-table/44201/6 "2021-09-24T04:13:14Z")

</div>

Hey @ben-duchy , after trying the method Teun and Indra suggested and when your query is resolved, please help us by making them as solutions​😉
