ciao!
io nn ho molta esperienza ma io farei:
if $tuavar1<>'' and $tuavar2<>'' ... then
$qyery="select........";

spero di esserti stata utile!