# Need help looping through HubDB rows and columns

**URL:** <https://community.hubspot.com/t/need-help-looping-through-hubdb-rows-and-columns/26077>\
**Category:** CMS Development\
**Created:** [September 28, 2020, 5:57pm UTC](https://community.hubspot.com/t/need-help-looping-through-hubdb-rows-and-columns/26077 "2020-09-28T17:57:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hayleyh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/hayleyh/32/58551_2.png) [@hayleyh](https://community.hubspot.com/u/hayleyh)\
**Post date:** [September 28, 2020, 5:57pm UTC](https://community.hubspot.com/t/need-help-looping-through-hubdb-rows-and-columns/26077/1 "2020-09-28T17:57:11Z")

</div>

Hi, I am trying to loop through columns, and then through rows coming from a HubDB table. Per the[Hubspot docs,](https://developers.hubspot.com/docs/cms/features/hubdb) it seems like I should be able to set the current row and current column ID I’m in in each of my loops to call \<current row\>.\<current column name\>, but that is not working for some reason. My code is below:

```lia-code-sample
{% set comp_table = hubdb_table(2686696) %}
{% set comp_table_rows = hubdb_table_rows(2686696) %}

<div class="bdt-table" id="bdt-table">
 <div class="container" id="spec-container">
 <div class="row">
 <div class="col-xs-12">
 <table>
 {% for column in comp_table.columns %}
 {% set current_col = column.name %}
 <tr>
 <td class="table-spec-name"> {{ column.label }} </td>
 {% for row in hubdb_table_rows(2686696) %}
 <td class="table-spec-name"> {{ row.current_col }} </td>
 {% endfor %}
 </tr>
 {% endfor %}
 </table>
 </div>
 </div>
 </div>
</div>

```

I really appreciate any help I can get with this, I have been trying to make this work for awhile and I’m really not getting anywhere. Thank you!

---

<div class="post-metadata">

**Author:** ![BarryGrennan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/barrygrennan/32/97794_2.png) [@BarryGrennan](https://community.hubspot.com/u/BarryGrennan)\
**Post date:** [September 28, 2020, 8:05pm UTC](https://community.hubspot.com/t/need-help-looping-through-hubdb-rows-and-columns/26077/2 "2020-09-28T20:05:40Z")

</div>

Hi Hayley,

This took me ages of messing around with it 😂 but I think I’ve figured it out.

It seems that you can’t call your variable “current\_col” by putting “row.current\_col”, instead you need to put “row|attr(current\_col)”

That’s not actually in the HubDB documentation from what I could see but I decided to play around with the hubl and found that this worked.

So the code I got to work looks like:

```lia-code-sample
{% set comp_table = hubdb_table(2686696) %}
{% set comp_table_rows = hubdb_table_rows(2686696) %}

<div class="bdt-table" id="bdt-table">
<div class="container" id="spec-container">
<div class="row">
<div class="col-xs-12">
<table>
{% for column in comp_table.columns %}
{% set current_col = column.name %}
<tr>
<td class="table-spec-name"> {{ column.label }} </td>
{% for row in comp_table_rows %}
<td class="table-spec-name"> {{ row|attr(current_col) }} </td>
{% endfor %}
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
</div>

```

Hope that works for you!

---

<div class="post-metadata">

**Author:** ![hayleyh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/hayleyh/32/58551_2.png) [@hayleyh](https://community.hubspot.com/u/hayleyh)\
**Post date:** [September 29, 2020, 1:51pm UTC](https://community.hubspot.com/t/need-help-looping-through-hubdb-rows-and-columns/26077/3 "2020-09-29T13:51:57Z")

</div>

Wow thank you so much, that works!!! I appreciate you taking the time!

---

<div class="post-metadata">

**Author:** ![BarryGrennan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/barrygrennan/32/97794_2.png) [@BarryGrennan](https://community.hubspot.com/u/BarryGrennan)\
**Post date:** [September 29, 2020, 2:06pm UTC](https://community.hubspot.com/t/need-help-looping-through-hubdb-rows-and-columns/26077/4 "2020-09-29T14:06:06Z")

</div>

Awesome! Glad to hear it worked for you. It’s an interesting problem.
