0

What is the best way to handle NULL values in a search form. I want to allow the user to search by 8 different criteria however if they leave a box blank I would like it to return all non null values for that column. I am able to assign a default value if the field is left blank but how can I change accountant to "IS NOT NULL"? Thank you for your time.

    if ($specialty_name == null){
        $specialty_name = 'Accountant';
    }

The SQL looks like this... WHERE specialty_name = 'Accountant'

0

1 Answer 1

3

Something like this:

if ($specialty_name == null) {
    $where = "WHERE specialty_name IS NOT NULL";
} else {
    $where = "WHERE specialty_name = '$specialty_name'";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.