Need Help!! with Search function using 4 different elements
Posted: Tue Aug 05, 2003 11:34 am
Hi,
I want to do a search function for my employee directory which can be searched by either:-
First Name
Last name
Department
Phone
My form looks something like this:-
##############################################
Right now I am very familiar how to search using only function but I am not sure how to construct a sql which can use either one of the information to do the search.
My current results page.. which only searches employees by department is as below:-
Would really appreciate if someone who either had experience doing this before or know how to do it could assist me. Thank You very much 
I want to do a search function for my employee directory which can be searched by either:-
First Name
Last name
Department
Phone
My form looks something like this:-
Code: Select all
<form ACTION="search_result2.php" method="get" name="lib">
<input type="hidden" name="dept" value="<? echo $rowїdeptid];?>">
First Name <input NAME="fname" size="20"><br>
Last Name <input NAME="lname" size="20">Code: Select all
Department:
<select name="dept">
<option value="" selected>Select a Department (optional)</option>
<?
$sql="select * from department
order by name";
$result=pg_query($sql);
for($i=0;$i<pg_numrows($result);$i++)
{
$arr=pg_fetch_array($result,$i);
echo "<OPTION value=".$arr["deptid"].">".$arr["name"];
}
?>
</select>Code: Select all
Work Phone<input NAME="phone" size="20><br>
<input TYPE="submit" name="submit" value="Search">
<input TYPE="Reset" name="Reset">
</form>Right now I am very familiar how to search using only function but I am not sure how to construct a sql which can use either one of the information to do the search.
My current results page.. which only searches employees by department is as below:-
Code: Select all
<?php
if(isset($_GET['dept']))
{
print("<table width="700" align="center">
<tr>
<td>
<table width="600">
<font face="Arial, Helvetica, sans-serif" size="3"><strong><u>Search Results</u></strong></font></td>
</tr><tr><td> </td></tr>");
searchTheDatabase(trim($_GET['dept']));
}
function searchTheDatabase($dept)
{
$query = "Select Distinct
employee.empid, employee.fname, employee.lname, emp_info.phone, department.name
FROM employee, department, emp_info
WHERE department.deptid = '$dept'
AND employee.empid = emp_info.empid
AND department.deptid = emp_info.deptid
ORDER by employee.fname";
print ("$query");
$dbResult = pg_query($query);
if(!pg_numrows($dbResult))
{
print("<tr><td><font face="Arial, Helvetica, sans-serif" size="2">Sorry Nothing was found matched your query:
</font></td></tr>");
}
else
{
print("<tr><td colspan="3"><font face="Arial, Helvetica, sans-serif" size="2">
The following matches were found to your query:
</font></tr>
<tr><td colspan="3"> </td></tr>");
?>