Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

build_range_where_condition()

Description

Build a SQL WHERE fragment and bound parameters from a list of integers and ranges.

Parses a comma-separated input string containing single integers and/or ranges
and can take optional wildcards (e.g. "1,3-5,10,12-")
Converts each item into a parameterized SQL condition:
- Single value: "<field> = ?"
- Range: "<field> BETWEEN ? AND ?"
- Sole wildcard: No filter, so 1=1 is used
- Range wildcard: "<field> >= ?"

All generated conditions are joined using OR and wrapped in parentheses.
Parameters are returned in the order they appear in the WHERE fragment.


where: string|null Parenthesized SQL fragment joined with OR when ok is true, otherwise null
params: array Ordered list of bind types and values
errors: string[] List of error messages when ok is false, otherwise empty

Parameters

ColumnTypeDefaultDescription
$input string Comma-separated list of integers and/or ranges (e.g. "1,3-5,10")
$field string Database column name to use in the generated SQL expressions
$max_val int 0 Optional upper bound for allowed values. Use 0 for no limit
$allow_wildcard bool If true, an asterisk can be used as a wildcard (e.g * for all, 10-* for 10 and above)

Return

array ok: bool True when the WHERE clause is successfully built, false on validation errors

This article was last updated 16th January 2026 17:35 Europe/London time based on the source file dated 16th January 2026 14:45 Europe/London time.