# Criteria

The XOOPS API has a class called **Criteria** to aid in database searches. The class is defined as such:

```php
Criteria Criteria (string $column, string $value = , string $operator = '=', mixed $prefix = , mixed $function = )
```

![](https://879096944-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5_mFcvcxsA3M1QhbWd%2F-M5b2crDSTdxTdAndKG-%2F-M5b2em_qMtSMOdmdnTj%2FCriteria.png?generation=1587645693064805\&alt=media)

It's handy for returning a list of objects from the **XoopsPersistableObjectHandler** class. Example:

```php
$criteria = new Criteria('id', $object_id); 
$array = $objecthandler->getObjects($criteria, false, false);
```

This returns $array as an array of all elements following the criteria! If the third argument of the getObjects method is true, it returns objects instead, handy for bulk manipulation!

The Criteria class only handles a single 'WHERE' condition. If you need multiple conditions, use **CriteriaCompo** in combination with Criteria. Here is an example out of the mailusers file:

```php
$criteria_object = new CriteriaCompo();
foreach ($criteria as $c) {
     list ($field, $op, $value) = split(' ', $c); 
     $criteria_object->add(new Criteria($field,$value,$op), 'AND');
}
```

If you have just a few simple conditions, you can just use

```php
$criteria_object = new CriteriaCompo();
$criteria_object->add(new Criteria($field1,$value1,$op1), 'AND');
$criteria_object->add(new Criteria($field2,$value2,$op2), 'AND');
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xoops.gitbook.io/xoops-modules-cookbook/core-classes/core/criteria.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
