Did you append: " order by state,city" at the end of your query statement?
(I am assuming that the above is but a piece of the whole statement)
BTW, if you want to search for regular expressions, use them, e.g.: " alv like '%$alv%'"
If you really need an exact match then use that, this will optimize your query performance.
I would also suggest an approach like:
if ($something)
$temp[] = " something like '%something%' ";
if ($foo)
$temp[] = " foo = 'foo'";
and at the end:
$tempquery = implode(" and ", $temp);
that will avoid the substring part of your code.
HTH