<?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: Display number of rows, as a number in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415837#M21593</link>
    <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/60000"&gt;@ben-duchy&lt;/a&gt;&amp;nbsp; Was meant ot be starter code.... Have you tried debugging it....? Maybe print out the rows....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it's a select there may be a different serialized representation such as a dictionary, list or something. I don't recall which naturally changes the access methdology.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe you can do:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;rows|selectattr("COLUMN_NAME_OF_SELECT.name", "equalto", "car")|length&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or, if that fails:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% set rows = hubdb_table_rows("TABLE ID", "COLUMN_NAME=OPTION VALUE") %}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, selectattr with a single query is preferred. If even that fails.... Great! As I said print it out, debug, and work with the data structure provided. If there's not a simple built in just iterate and build a counter. Whichever way.... there's certainly a way to get the count. Just figure out how to get there &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There's also a much cleaner way to write what you have written.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Mar 2021 12:43:20 GMT</pubDate>
    <dc:creator>Ntbrown</dc:creator>
    <dc:date>2021-03-08T12:43:20Z</dc:date>
    <item>
      <title>Display number of rows, as a number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415685#M21585</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Does anyone know how to display the number of rows, as a number?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Imagine you have a table with 10 rows with a column called 'transport'.&amp;nbsp;&lt;SPAN&gt;Each row will reference a particular type of transport, for example Train, Bus, Car, or Bike.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If for example 5 rows had 'car' selected, how do I display this as a number? &amp;nbsp;I assume it will be something along the lines of:&amp;nbsp;&lt;STRONG&gt;if transport.type='car' display row_count&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Am I getting close?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Mar 2021 21:15:49 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415685#M21585</guid>
      <dc:creator>ben-duchy</dc:creator>
      <dc:date>2021-03-06T21:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Display number of rows, as a number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415688#M21586</link>
      <description>&lt;P&gt;Entirely dependent on what you mean by "table". Is this HubDB or a custom table via the module? Either way... Just coallesce the results and display the sum.&amp;nbsp; Your post is vague, but I'm assuming you want something like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{# rows = module.rows or some other accessor if a module... or rows = hubdb_table_rows(tableId, other parameters) #}
{% set rows = pick a referencing methodology.... #}
{# count = rows|selectattr("column name in HubDB table or field in module group", "equalto", "mode of transportation")|length . So maybe.... #}
{% set numCars = rows|selectattr("mode_of_transportation", "equalto", "car")|length %}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can fill in the gaps... Or, add further detail.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Mar 2021 00:19:25 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415688#M21586</guid>
      <dc:creator>Ntbrown</dc:creator>
      <dc:date>2021-03-07T00:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: Display number of rows, as a number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415703#M21587</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/118753"&gt;@Ntbrown&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My apologies I forgot to specify which type of table... Yes I meant HubDB.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ok I'll try that, thanks&lt;/P&gt;</description>
      <pubDate>Sun, 07 Mar 2021 08:03:11 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415703#M21587</guid>
      <dc:creator>ben-duchy</dc:creator>
      <dc:date>2021-03-07T08:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: Display number of rows, as a number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415792#M21591</link>
      <description>&lt;P&gt;Unfortunately I couldnt get it to work.&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/73772"&gt;@Kevin-C&lt;/a&gt;&amp;nbsp; any thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have so far but the results just display 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;{% set rows = hubdb_table_rows(1234567) %}&lt;/P&gt;&lt;P&gt;{% set num_car = rows | selectattr ("transport_type","equalto","Car") | length %}&lt;BR /&gt;{% set num_train = rows | selectattr ("transport_type","equalto","Train") | length %}&lt;BR /&gt;{% set num_bus = rows | selectattr ("transport_type","equalto","Bus") | length %}&lt;BR /&gt;{% set num_bike = rows | selectattr ("transport_type","equalto","Bike") | length %}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;table&amp;gt;&lt;BR /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Number commuted by car:&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;{{ num_car }}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;BR /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Number commuted by Train:&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;{{ num_train }}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;BR /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Number commuted by Bus:&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;{{ num_bus }}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;BR /&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Number commuted by Bike:&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;{{ num_bike }}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;BR /&gt;&amp;lt;/table&amp;gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 09:45:26 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415792#M21591</guid>
      <dc:creator>ben-duchy</dc:creator>
      <dc:date>2021-03-08T09:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Display number of rows, as a number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415802#M21592</link>
      <description>&lt;P&gt;I've got it to work by changing the field type to a textbox.&amp;nbsp; What do I need to do with the above code to make it work for select list?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 09:51:57 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415802#M21592</guid>
      <dc:creator>ben-duchy</dc:creator>
      <dc:date>2021-03-08T09:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Display number of rows, as a number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415837#M21593</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/60000"&gt;@ben-duchy&lt;/a&gt;&amp;nbsp; Was meant ot be starter code.... Have you tried debugging it....? Maybe print out the rows....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it's a select there may be a different serialized representation such as a dictionary, list or something. I don't recall which naturally changes the access methdology.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe you can do:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;rows|selectattr("COLUMN_NAME_OF_SELECT.name", "equalto", "car")|length&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or, if that fails:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% set rows = hubdb_table_rows("TABLE ID", "COLUMN_NAME=OPTION VALUE") %}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, selectattr with a single query is preferred. If even that fails.... Great! As I said print it out, debug, and work with the data structure provided. If there's not a simple built in just iterate and build a counter. Whichever way.... there's certainly a way to get the count. Just figure out how to get there &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There's also a much cleaner way to write what you have written.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 12:43:20 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415837#M21593</guid>
      <dc:creator>Ntbrown</dc:creator>
      <dc:date>2021-03-08T12:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: Display number of rows, as a number</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415845#M21594</link>
      <description>&lt;P&gt;Spot on &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/118753"&gt;@Ntbrown&lt;/a&gt;&amp;nbsp;thanks&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm sure I tried the '.name' method between my last post and yours, but I must've had an error elsewhere.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 13:27:30 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Display-number-of-rows-as-a-number/m-p/415845#M21594</guid>
      <dc:creator>ben-duchy</dc:creator>
      <dc:date>2021-03-08T13:27:30Z</dc:date>
    </item>
  </channel>
</rss>

