System:Template:grabSelectArray

From Aspen Documentation

Returns an id=>value array for use in an html select element. May use distinct database table records, or ENUM values for fields.

Since 1.0

Contents

Arguments

array grabSelectArray (string $selectTable, string $selectField, [string $method = "ENUM"], [string $orderby = 'id'], [ string $select_id = 'id'], [string $where = false])

selectTable
Name of database table field is in.
selectField
Name of table column to pull from.
method
Whether to pull DISTINCT records, or the column ENUM values (if any).
orderby
If pulling distinct records, what field to order results by.
select_id
Primary key field, defaults to id. This value will be used as the key in the returned array.
where
Any additional WHERE conditions.

Returns

Returns an array.

Notes

  • The results of this function may be passed directly to getSelectOptions for printing out html select options.

Examples

This example grabs a distinct list of products from a database table, and passes the result to the getSelectOptions function.

$products_list = $this->grabSelectArray('products', 'product_name', 'DISTINCT');
print $this->getSelectOptions($products_list);