records_count()
Count how many records match a set of filters.
Syntax
records_count(table, filters?)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
table |
string or number | yes | The table's name, its database table name, or its numeric table id. Read the id from $table at run time (for example $table["fields"]["client"]["lookup_table"]); never type one into your code, because table ids change when a workspace is copied. A table whose name happens to be a number always wins over the table with that id. |
filters |
array | no | Filter conditions, in the same format as records_query(). Omit for a total count. |
Returns
An integer count.
Example
$open = records_count("tickets", [
["field" => "status", "op" => "!=", "value" => "closed"]
]);
if ( $open > 50 ) {
record_comment("dashboards", $record["_meta"]["id"], "Backlog over 50: " . $open);
}
Example output
63
Notes
- The count is exact, however many records match. There is no upper limit.
- Filters match exactly as in records_query().
- For sums, averages, minimums, maximums or counts per group, use records_aggregate().
See also: records_query(), records_aggregate()