Use db_select with multiple conditions of which one needs to apply My question is not a duplicate and it has complex conditions. Please let me explain. In my second condition, first I need to check if number value is correct (in first condition I checked complete opposite). If so, then check if there's a value in email column. Then show error message if there's a value in email column. My problem is I need to write first query (already done by me) and second query under the same 'db_select'

Checking for email value only activates if webform value matches a value in 'number' column.



I have a table containing two columns namely, 'number' and 'email'.

I need to run a db_select query to display same error message when a webform is submitted. My conditions are as follows:


Show error message if number value provided by webform does not matches a value in 'number' column
Show error message if number value provided by webform matches a value in 'number' column but corresponding 'email' column is not empty.


So far I'm able to show error message for the first condition.

db_set_active('mydatabase');    
    $query = db_select('mytable', 'c');
    $query-&gt;fields('c', array('number','email_address'))
    -&gt;condition('number', $phoneval, '=');
    $result = $query-&gt;execute()-&gt;fetchAll();

if (empty($result))
{
    form_set_error('phone_number','We have no record of that Assessment Number');
} 


How can I show the same error message for condition 2? I don not want to query the database again and thinking of using for db_or this.

Thanks
Syntax for db_or :

$or = db_or();
$or-&gt;condition();
$or-&gt;condition();
$query-&gt;condition($or);


For More Information