This is the routine called upon the form being submitted :
function searchStaff($search_text)
{
print "SEARCH TEXT : $search_text<br>\n";
$patterns = array ('/\bAND\b/i', '/\bOR\b/i', '/\bNOT\b/i');
$replace = array ("+ AND", "+ OR", "+ NOT");
$search_text = preg_replace ($patterns, $replace, $search_text);
//print "SEARCH TEXT : $search_text<br>\n";
if (preg_match("/\+/", $search_text))
{
$keywords = split("\+", $search_text);
$keyword_one = trim($keywords[0]);
$key_count = count($keywords);
for ($i=1; $i<$key_count; $i++)
{
if (preg_match("/OR/", $keywords[$i]))
{
$keywords[$i] = substr($keywords[$i], 3, strlen($keywords[$i]));
$keywords[$i] = trim($keywords[$i]);
if ((count($or) == 0) && ($i == 1)) $or[0] = $keyword_one;
$or[count($or)] = $keywords[$i];
}
else if (preg_match("/AND/", $keywords[$i]))
{
$keywords[$i] = substr($keywords[$i], 4, strlen($keywords[$i]));
$keywords[$i] = trim($keywords[$i]);
if ((count($and) == 0) && ($i == 1)) $and[0] = $keyword_one;
$and[count($and)] = $keywords[$i];
}
else if (preg_match("/NOT/", $keywords[$i]))
{
$keywords[$i] = substr($keywords[$i], 4, strlen($keywords[$i]));
$keywords[$i] = trim($keywords[$i]);
if ((count($not) == 0) && ($i == 1)) $and[0] = $keyword_one;
$not[count($not)] = $keywords[$i];
}
}
$query = "select title, fname, lname, email, homepage, room, phone_extn, position, keywords from coordinators where ";
if (count($and) != 0)
{
$and_count = count($and);
for ($k=0; $k<$and_count; $k++)
{
if ($k == 0) $and_query = "(keywords like '%$and[$k]%' ";
else $and_query .= " and keywords like '%$and[$k]%'";
}
$and_query .= ")";
$subquery .= $and_query;
}
if (count($or) != 0)
{
$or_count = count($or);
for ($k=0; $k<$or_count; $k++)
{
if ($k == 0) $or_query = "(keywords like '%$or[$k]%' ";
else $or_query .= " || keywords like '%$or[$k]%'";
}
$or_query .= ")";
if (count($and) == 0) $subquery .= $or_query;
else $subquery .= " || $or_query";
}
if (count($not) != 0)
{
$not_count = count($not);
for ($k=0; $k<$not_count; $k++)
{
if ($k == 0) $not_query = "(keywords not like '%$not[$k]%' ";
else $not_query .= " and keywords not like '%$not[$k]%'";
}
$not_query .= ")";
if (! empty($subquery)) $subquery = "($subquery) and $not_query";
else $subquery .= $not_query;
}
$query .= $subquery." order by lname";
}
else $query = "select title, fname, lname, email, homepage, room, phone_extn, position, keywords from coordinators where keywords like '%$search_text%' order by lname";
//print "QUERY : $query<br>\n";
$link = MySql_DBConnect();
$result = mysql_query($query, $link);
mysql_close();
if (mysql_errno() == 0) $numresults = mysql_numrows($result);
else $numresults = 0;
print "<a name=\"results\"></a>\n";
print "<span class=\"subheading\">Search results</span><br>\n";
if ($numresults != 0) $people = readPeopleDir();
else print "<i>No results were returned.</i><br><br>\n";
for ($i=0; $i<$numresults; $i++)
{
$name = mysql_result($result, $i, "title")." ".mysql_result($result, $i, "fname")." ".mysql_result($result, $i, "lname");
$email = mysql_result($result, $i, "email");
if (in_array($email, $people)) $people_page = true;
else $people_page = false;
$homepage = mysql_result($result, $i, "homepage");
$room = mysql_result($result, $i, "room");
$phone = mysql_result($result, $i, "phone_extn");
$position = mysql_result($result, $i, "position");
$interests = mysql_result($result, $i, "keywords");
// Replace DB delimiter '|' with ' ,'
$interests = preg_replace('/\|/', ', ', $interests);
print "<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" width=\"99%\">\n";
print " <tr>\n";
print " <td>\n";
print "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" width=\"100%\">\n";
print " <tr>\n";
print " <td width=\"70%\">\n";
print " <table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n";
print " <tr>\n";
print " <td>\n";
if (! $people_page) print " <b>$name</b><br>\n";
else print " <a href=\"http://www.ee.usyd.edu.au/theschool/people/$email.html\"><b>$name</b></a><br>\n";
print " <b>$position</b>\n";
print " </td>\n";
print " <td valign=\"top\">";
if (! empty($homepage)) print " <a href=\"#\" onClick=\"window.open('$homepage', ''); return false;\"><img src=\"/ugrad/Images/home.gif\" border=\"0\"></a>";
else print " ";
print " </td>\n";
print " </tr>\n";
print " </table>\n";
print " </td>\n";
print " <td align=\"right\" valign=\"middle\">\n";
if (! empty($email))
{
if (! preg_match("/^(.*\@.*)$/", $email)) $email .= "@ee.usyd.edu.au";
print " <a href=\"mailto:$email\"><img src=\"/ugrad/Images/mail.gif\" border=\"0\"></a>\n";
}
else print " \n";
print " </td>\n";
print " </tr>\n";
print " <tr>\n";
print " <td bgcolor=\"#EFEFEF\" colspan=\"2\">\n";
if (! empty($room)) print " <b>Room:</b> $room \n";
if (! empty($phone)) print "<b>Phone:</b> 9351 $phone<br>\n";
else print "<br>\n";
print " <b>Areas of Interest:</b><br>\n";
print " <span style=\" width: 99%; text-align: justify\">$interests</span><br>\n";
print " </td>\n";
print " </tr>\n";
print "</table>\n";
print " </td>\n";
print " </tr>\n";
print "</table><br>\n";
}
}
Mayu