i have a search form where a user can search for certain fields in the database. if a field is left empty it can match anything including null. If something is entered in the field, it should match to that field including wildcards.
I’m using php as server-side language.
The issue is, if a search field is empty, I can’t just use php and convert it to ‘%’ as it will not match null. (assuming where clause is fieldA like $value). Also I can’t use “fieldA like $value OR fieldA IS NULL” because then it will return all matching fields and fields that are null.
Is there a (rather simple way) to to this in an SQL Statement? Currently I build the where clause in PHP and it is rather cumbersome.
You’re attempted solution is checking the wrong item for nullability.
You need a record to always yield TRUE if the parameter is NULL, or TRUE if the field matches the parameter…