php - Skip values in case they are empty -
i need skip values in case, empty. data in database looks similary:
gender : man hair : blonde eyes : blue figure : slim gender : woman hair : blonde eyes : blue figure : slim
when use query:
select * people figure = 'slim' , hair = 'blonde' , eyes = '' , gender = 'man';
it returns me nothing, because eyes
empty. data form in php , empty data fields, user don't fill.
can me, how can fix it? driver database use pdo.
you need step through values 1 one:
$sql = "select * people " $appender = ""; if ( !empty($gender) ) { $sql .= ( $appender . " gender = '" . $gender . "'"); $appender = " , "; } if ( !empty($hair) ) { $sql .= ( $appender . " hair= '" . $hair. "'"); $appender = " , "; } ... ...
Comments
Post a Comment