How to deal with null values submitted by multi-condition queries? Table 1 contains brands, periods, and models
Board (BMW, ford, aodi)
Year (2013)
Type (car, suv, mpv)
I have made three drop-down menus for users to select and query
1. Select 2013 in BMW and year on the board, but the third type is not selected,
However, when the type field is executed, null is sent, and the value is equal
Board = 'BMW 'AND year = "2013" AND type =''
If the field is not null, all models of BMW and 2013 are created,
Board = 'BMW 'AND year = "2013" AND type is not null
Or
Board = 'BMW 'AND year = "2013"
How to do this,
Reply to discussion (solution)
Refer to the writing method below
$where = array();if($board){ $where[]=" board='$board'";}if($year){ $where[]=" year='$year'";}....$sql.=(!empry($where)) ? ' where ' . implode(' and ', $where) : '';
Set $ _ POST
$ _ POST = array ('board' => 'BMW ', 'year' => '000000', 'type' => '');
Then
$ W = array ();
Foreach ($ _ POST as $ k => $ v ){
If (! Empty ($ v) $ w [] = "$ k = '$ V '";
}
$ Where = join ('and', $ w );
Get
Board = 'BMW 'and year = '20140901'