# where

Parameters below can be used to the following methods:

{% content-ref url="../find" %}
[find](https://jls-organization-3.gitbook.io/projecthyper/features/quickstart/find)
{% endcontent-ref %}

{% content-ref url="../findone" %}
[findone](https://jls-organization-3.gitbook.io/projecthyper/features/quickstart/findone)
{% endcontent-ref %}

{% content-ref url="../update" %}
[update](https://jls-organization-3.gitbook.io/projecthyper/features/quickstart/update)
{% endcontent-ref %}

{% content-ref url="../delete" %}
[delete](https://jls-organization-3.gitbook.io/projecthyper/features/quickstart/delete)
{% endcontent-ref %}

{% content-ref url="../softdelete" %}
[softdelete](https://jls-organization-3.gitbook.io/projecthyper/features/quickstart/softdelete)
{% endcontent-ref %}

{% content-ref url="../count" %}
[count](https://jls-organization-3.gitbook.io/projecthyper/features/quickstart/count)
{% endcontent-ref %}

{% content-ref url="../paginate" %}
[paginate](https://jls-organization-3.gitbook.io/projecthyper/features/quickstart/paginate)
{% endcontent-ref %}

Where conditions are flexible you may use it like these:

```php
// Inline
$db->news->find(array('id' => 1));

// Inside where object
$db->news->find(
    array(
        'where' => array(
            'id' => 1
        )
    )
);
```

**Using Primary ID:**

<pre class="language-php"><code class="lang-php">$db->{table}->{method}(1);
<strong>$db->{table}->{method}(array('id' => 1));
</strong>$db->{table}->{method}(
    array(
        'where' => array(
            'id' => 1
        )
    )
);
</code></pre>

Example:

```php
$db->news->find(1);
$db->news->find(array('id' => 1));
$db->news->find(
    array(
        'where' => array(
            'id' => 1
        )
    )
);
```

**Using other columns:**

```php
$db->{table}->{method}(array('status' => 'ACTIVE'));
```

Example:

```php
$db->news->find(array('status' => 'ACTIVE'));
$db->news->find(array(
        'status' => 'ACTIVE',
        'created_at' => '2024-12-11 00:00:00'
    )
);
$db->news->find(array(
        'where' => array(
             'status' => 'ACTIVE',
             'created_at' => '2024-12-11 00:00:00'
        )
    )
);
```

***

**Complex Conditions:**

{% hint style="info" %}
The conditions below can be wrapped inside the "**where"** object/array
{% endhint %}

This scopes the equal, like, greater than, greater than or equal, etc.

**equal (=)**

> SELECT \* FROM news WHERE id = 1

```php
$db->news->find(
    array(
        'id' => array(
            'eq' => 1
        )
    )
);
// or 
$db->news->find(array('id' => 1));
```

**in ( IN (....)  )**

> SELECT \* FROM news WHERE id in (1, 2, 3)

```php
$db->news->find(
    array(
        'id' => array(
            'in' => array(1, 2, 3)
        )
    )
);
```

**gt ( > $ )**

> SELECT \* FROM news WHERE id > 5

```php
$db->news->find(
    array(
        'id' => array(
            'gt' => 5
        )
    )
);
```

**gte ( >= $ )**

> SELECT \* FROM news WHERE id >= 5

```php
$db->news->find(
    array(
        'id' => array(
            'gte' => 5
        )
    )
);
```

**lt ( < $ )**

> SELECT \* FROM news WHERE id < 5

```php
$db->news->find(
    array(
        'id' => array(
            'lt' => 5
        )
    )
);
```

**lte ( <= $ )**

> SELECT \* FROM news WHERE id <= 5

```php
$db->news->find(
    array(
        'id' => array(
            'lte' => 5
        )
    )
);
```

**like ( LIKE '%$%' )**

> SELECT \* FROM news WHERE name like '%test%'

```php
$db->news->find(
    array(
        'id' => array(
            'like' => 'test'
        )
    )
);
```

**between ( BETWEEN $ and $ )**

> SELECT \* FROM news WHERE created\_at between '2024-01-01' and '2024-12-31'

```php
$db->news->find(
    array(
        'id' => array(
            'between' => array('2024-01-01', '2024-12-31')
        )
    )
);
```

***

**How about the or's and the and's ?**

**or**

> SELECT \* FROM news WHERE name like '%your test%' or name = 'my test'

```php
$or_condition = array(
    'name' => array(
        'or' => array(
            'like' => 'your test',
            'eq' => 'my test',
        )
    )
);
```

**and**

> SELECT \* FROM news WHERE id ≥ 1 and id <= 20

```php
$and_condition = array(
    'id' => array(
        'and' => array(
            'gte' => 1,
            'lte' => 20
        )
    )
);
// or
$and_condition = array(
    'id' => array(
        'gte' => 1,
        'lte' => 20
    )
);
```

**not\_null**

> SELECT \* FROM news WHERE name IS NOT NULL

```php
$not_null = array(
    'name' => array(
        'not_null' => true
    )
);
```

**null**

> SELECT \* FROM news WHERE name NULL

```php
$is_null = array(
    'name' => array(
        'null' => true
    )
);
```

***

**Combining Conditions**

> SELECT \* FROM news&#x20;
>
> WHERE name like '%your test%' and name = 'my test'&#x20;
>
> &#x20; and created\_at between 'date1' and 'date2'&#x20;

```php
$where = array(
    'name' => array(
        'like' => 'your test',
        'eq' => 'my test'
    ),
    'created_at' => array(
        'between' => array(
            'date1',
            'date2'
        )
    )
)
```
