The unset is giving the parse error. I'm not sure it's allowed inside such a construct. It is better practice to use the ternary operator like so:
$query[0] = ($author ? "pub_author LIKE %'$author'%" : NULL);
$query[1] = ($title ? "pub_title LIKE %'$title'%" : NULL);
$query[2] = ($projectid ? "pub_projectid_ = $projectid" : NULL);
If it's important to you to use unset instead of assigning NULL values to the array, then use full if-else statements:
if ($author) {
$query[0] = "pub_author LIKE %'$author'%";
} else {
unset($query[0]);
}
Of course, in that case, if $author doesn't contain anything, then $query[0] won't even exist. In my first example, it will exist, and contain nothing. I can see where you would want to use unset.
When building your query, however, you may just want to do this:
unset($query);
if ($author) $query[] = "pub_author LIKE %'$author'%";
if ($title) $query[] = "pub_title LIKE %'$title'%";
if ($projectid) $query[] = "pub_projectid_ = $projectid";
That way, $query only contains your search terms, which is what I think you were trying to do in the first place, right?