get_records — Get a set of records from the database.¶
get_records($recordType, $params = array(), $limit = 10)¶
Get a set of records from the database.
- $recordType (string) – Type of records to get.
- $params (array) – Array of search parameters for records.
- $limit (int) – Maximum number of records to return.
array An array of result records (of $recordType).
get_records() retrieves different kind of records from the database. You can use it when other record queries don’t work for you.
$items = get_records('Item',array('tags'=>$itemTags, 'range'=>$itemIds, 'collection'=>$itemCollection, 'type'=>$itemType),50);
This example uses four different parameters in the
$params array to narrow down the range of items selected:
tagsuses a string of tag names to lookup items by tag
rangeallows you to select records by ID ranges. For example:
collectionallows you to select a given collection ID.
typeallows you to select a given item type by ID.
$exhibits = get_records('Exhibit', array('slug'=>$exhibitSlugs, 'tags'=>$exhibitTags), 50);
This example uses two different parameters in the
$params array to narrow down the range of exhibits selected:
slugallows you to select exhibits by comma-separated slugs
tagsuses a string of tag names to lookup exhibits by tag
In both cases, you can then iterate through the array of records that is returned in order to display them or perform further processing.
The complete list of parameters that you can filter records by can be found in the model objects that extend Omeka_Db_Table. See list of classes in the
application/models/Table directory. In particular, look at the
applySearchFilters() method that is attached to each class.