Assuming you have two vars, lname and initial, something like this:
$query .= "select * from table where ";
$lpart = "lname like '%$lname%' ";
$ipart = "initial = '$initial' ";
if (eregi("^[a-z]{1}$",$initial)) $i=1;
else $i=0;
if (strlen($lname)>0) $l=1;
else $l=0;
if ($i && $l){
$query.= $ipart."and ".$lpart;
}else if ($i && !$l){
$query.= $ipart;
} else if (!$i && $l){
$query.= $lpart;
} else {
print "Gimme a fricken bone here people";
}
That code's not tested, but the regex works. Here's the disection of it:
[a-z]{1}$
^ left side anchor
[a-z] any char from a to z
{1} one occurance of the [a-z]
$ right anchor.
so, it means one character, and one character only, from a-z. using eregi means it acts like [a-zA-Z].