Say I have this query:
$qry = 'SELECT p.id FROM products p
WHERE p.type = :type AND p.parent = :parent';
If I wanted to make "type" optional then the only way I know how to do it would be to do something like this:
$qry = 'SELECT p.id FROM products p
WHERE p.parent = :parent';
if(isset($type))
{
$qry .= 'AND p.type = :type';
}
Is this the best way? I am wondering if there is a way I can keep it like the original, and use some sort of parameter to indicate that it is optional... For example if $type = "*" then pull all types.
Whats the best way to do this?