php - Sql conditional query parameters (include a parameter only when the corresponding form field is filled) -


i'm writing php program using mssql have long query many parameters , quite big database. how solve parameter in query gets included when corresponding form field filled?

example:

select * users userdid='' , status='' , ... 

lets admin tool seraching users want include and parameter='' sections corresponding form field has been filled.

i check each form field , stich query feel there easier , more elegant way.

brother hope go bellow algorithm

  1. create globel variable condition.
  2. check first input value not blank, if not blank put globel variable .
  3. so on other fileds.
  4. after input check globel varriable content condtion user submited.

sample example.

var a=""; if(txtuser!="") { = a==""?"username= ".txtuser:"username= ".txtuser; }  if(txtcountry!="") { = a==""?"country= ".txtcountry:a." , country= ".txtcountry; } 

a variable condition


Comments