# hubDB filtering

**URL:** <https://community.hubspot.com/t/hubdb-filtering/10374>\
**Category:** CMS Development\
**Created:** [September 25, 2018, 1:43pm UTC](https://community.hubspot.com/t/hubdb-filtering/10374 "2018-09-25T13:43:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cph\_design](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cph_design/32/51304_2.png) [@cph\_design](https://community.hubspot.com/u/cph_design)\
**Post date:** [September 25, 2018, 1:43pm UTC](https://community.hubspot.com/t/hubdb-filtering/10374/1 "2018-09-25T13:43:40Z")

</div>

Hello,  
I am working on a database driven page of training opportunities and running into some issues with filtering.  
The end goal is to have a block of text come up if a certain combination or varibales are not found in the tabl, however I don’t want this to repeat for each row in the table I was to only see this message once.

Here is a snippet of current code I am using

```auto
{# Finance Tab #}
 <div class="finance-tab padding40tb">
 <h2>Finance</h2>
 {% if table == [] %}
 <p class='align-center'>Sorry, there is an error on this page.</p>
 {% else %}
 <div class="trainings">
 {% rich_text "my_rich_text" label="Enter text here" html="<p>Take some time to get the most out of Church360° Members by attending one of our free training webinars!</p>" %}
{# Finance Webinars #}
 <div class="webinars padding20tb">
 <div class="section-subheader">{% header "my_header" header_tag="h3", overrideable=True, value="Webinars", label="Header" %}</div>
 <div class="table-header">
 <div class="table-header-row">
 <div class="box box1">Title</div>
 <div class="box box2">Date</div>
 <div class="box box3">Time</div>
 <div class="box box4">Link</div>
 </div>
 </div>
 {% for row in table|sort(False, False, 'date') %}
 {% if row["ss-module"].name is containing "Finance" %} 
 			{% if row["type"].name is containing "Webinar" %}
 <div class="boxes">
 <div class="boxes-row">
 <div class="box box1">{{ row.name }}</div>
 <div class="box box2"> {{ row.date|datetimeformat('%B %e, %Y') }}</div>
 <div class="box box3">{{ row.time }}</div>
 <div class="box box4"><a href="{{ row.url }}" target="_blank" class="cta-green-solid">Register</a></div>
 </div>
 </div>
 {% endif %}
 					{% endif %}
 {% endfor %}
 </div>
{# End Finance Webinars #}
{# Finance Seminars #}
 <div class="seminars padding20tb">
 <div class="section-subheader">{% header "my_header_2" header_tag="h3", overrideable=True, value="Seminars", label="Header" %}</div>
 <div class="table-header">
 <div class="table-header-row">
 <div class="box box1">Title</div>
 <div class="box box2">Date</div>
 <div class="box box3">Time</div>
 <div class="box box4">Link</div>
 </div>
 </div>
 {% for row in table|sort(False, False, 'date') %}
 {% if row["ss-module"].name is containing "Finance" and row["type"].name is containing "Seminar" %}
 <div class="boxes">
 <div class="boxes-row">
 <div class="box box1">{{ row.name }}</div>
 <div class="box box2"> {{ row.date|datetimeformat('%B %e, %Y') }}</div>
 <div class="box box3">{{ row.time }}</div>
 <div class="box box4"><a href="{{ row.url }}" target="_blank" class="cta-green-outline">View Recording ►</a></div>
 </div>
 </div>
 {% endif %}
 {% endfor %}
 </div>
{# End Finance Seminars #}
 </div>
 {% endif %}
 </div>
{# End Finance Tab #}

```

Here is a page with this working: [http://www-concordiatechnology-org.sandbox.hs-sites.com/shepherds-staff/training?hs\_preview=cLkOXaSD-6174656901](http://www-concordiatechnology-org.sandbox.hs-sites.com/shepherds-staff/training?hs_preview=cLkOXaSD-6174656901)

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [September 25, 2018, 7:08pm UTC](https://community.hubspot.com/t/hubdb-filtering/10374/2 "2018-09-25T19:08:33Z")

</div>

[@cph\_design](https://community.hubspot.com/t5/user/viewprofilepage/user-id/13764) an else statement applying the block of text would apply the block of text for each failed iteration.

I like to use jquery to show a prexisting div with the message if the elements wrapping the outputed items does not exist:

```auto
$(document).ready(function(){
 var container = $('.container_class'),
 items = container.find('.item_class'),
 message = container.find('.message');

 if (items.length <= 0) {
 message.show();
 }
});

```

Need help? [Hire Us Here](https://www.upwork.com/o/companies/_~0124e15ff34efb3871/)

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [September 26, 2018, 11:52am UTC](https://community.hubspot.com/t/hubdb-filtering/10374/3 "2018-09-26T11:52:51Z")

</div>

[@cph\_design](https://community.hubspot.com/t5/user/viewprofilepage/user-id/13764) - I like @Jsum answer because of scoping issues within **for loops** can make it impossible to keep a running total of things outside of a for loop (meaning, you can’t set variables or override variables outside of the for loop).

But, if you want to count the results, you could use the follow:

**from within the loop:**

`{{loop.length}}`

**from outside of the loop:**

`{{table|sort(False, False, 'date')|length}}`

* * *

If this answer helped, please, mark as solved 😄

* * *

[tim@belch.io](mailto:tim@belch.io) | [forms.belch.io](https://forms.belch.io) | Design your own Beautiful HubSpot Forms; No coding necessary.

Drop by and say Hi to me [on slack](http://slack.belch.io/).
