Problem Creating a "two word" search (PHP & Po
Posted: Mon Aug 04, 2003 10:00 am
Hi there,
I am new to php and having difficulty in doing a two word search in my employee directory database I have created. I can either search with last name or first name, but if I put in both names then I am not getting any results. I am using Posgresql as my back-end. I believe Mysql has this function called CONCAT.. I tried to use this function.. but does not seem to work. Any ideas are highly appreciated.
Thank you in advance
My current code:-
search_result.php
I am new to php and having difficulty in doing a two word search in my employee directory database I have created. I can either search with last name or first name, but if I put in both names then I am not getting any results. I am using Posgresql as my back-end. I believe Mysql has this function called CONCAT.. I tried to use this function.. but does not seem to work. Any ideas are highly appreciated.
Thank you in advance
Code: Select all
<?php
<form action="search_result.php" method="post" name="lib">
<input type="text" name="emp">
<input type="submit" name="search" class="submit_button"value="GO">Code: Select all
<?php
if(isset ($_POST['emp']))
{
print("<table width="700" align="center">
<tr>
<td>
<table width="600">
<font face="Arial, Helvetica, sans-serif" size="">
<strong><u>Search Results</u></strong></font></td>
</tr>
<tr>
<td> </td>
</tr>");
searchTheDatabase(trim($_POST['emp']));
}
function searchTheDatabase($emp)
{
$query = "Select
employee.empid, employee.fname, employee.lname,
emp_info.phone, department.name
FROM employee, department, emp_info
WHERE (lower(lname) Like lower('%".$_POST['emp']."%')
OR lower(fname) Like lower('%".$_POST['emp']."%'))
AND employee.empid = emp_info.empid
AND department.deptid = emp_info.deptid
ORDER by employee.fname";
$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:
<strong><i>$emp</i></strong></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:
<strong><i>$emp</i></strong></font></tr>
<tr><td colspan="3"> </td></tr>");
print("<tr><td width="220">
<font face="Arial, Helvetica, sans-serif" size="2">
<b>Name</b></font></td>
<td><font face="Arial, Helvetica, sans-serif" size="2">
<b>Department</b></font></td>
<td><font face="Arial, Helvetica, sans-serif" size="2">
<b>Phone</b></font></td>
</tr>");
?>