Oct 10, 201711:05 AM - edited Oct 10, 201711:09 AM
Participant
Trouble sorting DB queries by date
SOLVE
"Hi there,
I have a DB setup with all my companies events and query them onto my event page. I recently wanted to add some functionality that if I was to add another DB entry for an event before the last DB entry it would appear in the right spot on the event page. I want to use a filter to sort my DB entries by date before they are queried to the page. I found this piece of code to use:
{% for row in hubdb_table_rows(<tableId>, <filterQuery>) %}
the value for row {{ row.hs_id }} is {{ row.<column name> }}
{% endfor %}
I thought the filterQuery "orderBy=-bar" seems like it could be used to sort by date. But my DB query setup is a little different from what has been displayed above and I'm not sure how to get this to work on my own page.
I currently use:
{% set table = hubdb_table_rows(673755, queryparam)%}
and I tried to implement the code this way:
{% set table = hubdb_table_rows(673755, queryparam, orderBy=event_date)%}
I also tried a few other ways but can't seem to patch this together. Can someone explain what I'm doing wrong?
The `hubdb_table_rows()` function only accepts 2 parameters, so adding a 3rd won't do anything. What you'll need to do is append `&orderBy=event_date` to `queryparam`, wherever that is being defined.
Instead of:
{% set table = hubdb_table_rows(673755, queryparam, orderBy=event_date)%}
You'd want:
{% set queryparam = "orderBy=event_date" %}
{% set table = hubdb_table_rows(673755, queryparam)%}
The `hubdb_table_rows()` function only accepts 2 parameters, so adding a 3rd won't do anything. What you'll need to do is append `&orderBy=event_date` to `queryparam`, wherever that is being defined.
Instead of:
{% set table = hubdb_table_rows(673755, queryparam, orderBy=event_date)%}
You'd want:
{% set queryparam = "orderBy=event_date" %}
{% set table = hubdb_table_rows(673755, queryparam)%}