sql选择AND如果发布或如果没有

i am doing a search form and all the fields are optional

so if i did a select statement with AND.... if there is a field not posted i'll not get any result and if i did select statement with OR i'll get an extensive result

    $result= mysqli_query($con,"SELECT * FROM property WHERE 
   (Typ='$_POST[typ]' OR Purpose='$_POST[purpose]' OR City='$_POST[city]' OR a='$_POST[add]')
                  GROUP BY p_num ORDER BY Add_date DESC ");

is there a way to to specific the posted fields and do the select statement for them

check if the user have given input or not using isset()

Before answering, a first remark : you should use prepared statements as doing it like this is highly unsecure.

Now, for the answer, you should do any manipulation/filtering/testing with your $Post variables on beforehand, generating your SQL query on the way, and finally using this sql query you built bits by bits to query the database.