I want to fetch the count of all the rows in a table, so here is my statement:
{% set lengthTeam = hubdb_table_rows(9999999)|length %}
After executing, lengthTeam is 0. If I add a query, then I get a length > 0.
i.e : {% set lengthTeam = hubdb_table_rows(9999999, “city=Roseville”)|length %}
However, if I use the “ne” comparison operator, I get a length of zero, which I know is invalid. I should get back many rows.
i.e : {% set lengthTeam = hubdb_table_rows(9999999, “city__ne=Roseville”)|length %}
Anyone know what’s happening or what I am missing?
Hi @jmalone30,
There might be a more direct/elegant solution that I am not aware of, but in order to get the length, you can apply the length filter to the variable:
{% set my_rows = hubdb_table_rows(9999999) %}
{% set lengthTeam = my_rows|length %}
Hope this helps!
I have tried this also, and still get 0 length. The point is I am fetching 0 records, which is inconceivable!
{% set team = hubdb_table_rows(9999999) %}
{% set lengthTeam = team|length %}
length team = {{ lengthTeam }}
What am I doing wrong?
That’s odd.
Are you seeing anything returned from the {{ team }} variable?
{% set team = hubdb_table_rows(9999999) %}
{% set lengthTeam = team|length %}
<p>lengthTeam = {{ lengthTeam }}</p>
<p>team = {{ team }}</p>
No, but if I query the same table with a filter, I do get results back. But none of the comparison operators work.
This works:
{% set query = “orderBy=-hs_created_at” ~ “&city=Roseville” %}
{% set team= hubdb_table_rows(9999999, query) %}
This does not work:
{% set query = “orderBy=-hs_created_at” ~ “&city__ne=Roseville” %}
{% set team= hubdb_table_rows(9999999, query) %}
and, as I said before, this does not work:
{% set team= hubdb_table_rows(9999999) %}
I think I figured this out! I wasn’t familiar with using debug mode when rendering the page. Once I turned it on, I see this error:
TemplateError{severity=WARNING, reason=OVER_LIMIT, item=FUNCTION, message=‘Page is over hubdb_table_rows call limit of 10. Result from hubdb_table_rows will be empty.’
So I need to re-examine the page to reduce the hubdb_table_rows calls.