<?php
$a = $_POST['a'];
$b = $_POST['b'];
$search = "";
if(!empty($a))
{
$search .= " and a like '%$a%' ";
}
if(!empty($b))
{
$search .= " and a like '%$a%' ";
}
$sql = mysql_query("select * from table where some_col<>'' $search order by something ");
// code ที่เหลือ ......................
?>