Do you have DataAssist? The easiest way to get a dynamic where clause without hand coding is to use DataAssist search.
You could also hand code if statements and build the query dynamically if you want to write php by hand the same way you did the php.