Does anyone know how to display the number of rows, as a number?
Imagine you have a table with 10 rows with a column called 'transport'. Each row will reference a particular type of transport, for example Train, Bus, Car, or Bike.
If for example 5 rows had 'car' selected, how do I display this as a number? I assume it will be something along the lines of: if transport.type='car' display row_count
@ben-duchy Was meant ot be starter code.... Have you tried debugging it....? Maybe print out the rows....
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.
{% set rows = hubdb_table_rows("TABLE ID", "COLUMN_NAME=OPTION VALUE") %}
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 🙂
There's also a much cleaner way to write what you have written.
@ben-duchy Was meant ot be starter code.... Have you tried debugging it....? Maybe print out the rows....
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.
{% set rows = hubdb_table_rows("TABLE ID", "COLUMN_NAME=OPTION VALUE") %}
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 🙂
There's also a much cleaner way to write what you have written.
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. Your post is vague, but I'm assuming you want something like this?
{# 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 %}
You can fill in the gaps... Or, add further detail.