0

like in my previous posts, I have a search.php file and a searchResults.php file. There is a drop down menu on the search.php file and it has various methods to search a table in my DB like EmployeeID, EmpName, Team, Department, and Manager. i got all the rest working; however, i need to find a way for the searchResults.php file to distinguish if either the user is entering a managerID or a manager Name without adding another selection on the drop down menu. ie) if the user selects search for Manager in the menu and types in an ID number, the searchResult.php file will be able to know if an ID was entered or a name. How can I do this, right now this is what I have:

case ($method=='ManagerID'):
    if(empty($_POST['query']))
	{	
	exit("Please Fill in the Manager ID or name you want to search.
Click <a href=search.php>here</a> to go back.</p>");
	}
	else
	{
	echo"<i>Your search for {$_POST['query']} had the following results:</i>";
	mysql_select_db("titans", $con);
	$XX = "<font color=red>No Record Found</font>";
	$method=$_POST['searchType'];
	$search=$_POST['query'];
	$query = mysql_query("SELECT * FROM Employee WHERE $method = '$search'");
	$numrow = ceil(mysql_num_rows(($query)));///changed
	$space=' ';	
	echo($var3);
if($query!=NULL)	
{
	echo"<table class='full'>";
	echo"<th></th><th>ID</th><th>Employee Name</th><th>Title</th><th>Team</th><th>Department</th></tr>";
	while ($row = mysql_fetch_array($query))
	{
		$variable1=$row["EmployeeFName"];
		$variable2=$row["EmployeeLName"];
		$variable3=$row["EmployeeID"];
		$variable4=$row["EmployeeDepart"];
		$variable5=$row["EmployeeTeam"];
		$variable6=$row["ManagerID"];
		$variable7=$row["EmployeeTitle"]; 
if($variable3==$_POST['query'])
{
echo"<tr><td class='view'><form action='employee.html' method='post'><div><input type='submit' value='View' class='button' /></div></td><td name='userID' class='id'>{$variable3}</td></form><td name='userName' class='record'>{$variable1}{$space}{$variable2}  </td><td name='userTitle' class='record'>{$variable7}</td><td name='userTeam' class='record'>{$variable5}</td><td name='userDept' class='record'>{$variable4}</td></tr>";
}

	} 
if (!$variable3)
{
print ("$XX");
exit('<p> Click <a href=search.php>here</a> to go back.</p>');
}

}

else
{
		//////////If user enters a Full name this will parse the string
	$full = $_POST['query'];
	$n = sscanf($full, "%s %s", $first, $last);
	$Mangr= sqlQuery("SELECT * FROM Employee WHERE EmployeeFName like '$first' AND EmployeeLName like '$last'");
	////////########################
	echo"<table class='full'>";
	echo"<th></th><th>ID</th><th>Employee Name</th><th>Title</th><th>Team</th><th>Department</th></tr>";
	if($last==NULL)
	{
		$Mangr= sqlQuery("SELECT * FROM Employee WHERE EmployeeFName like '$first'");
	while ($row = mysql_fetch_array($Mangr))
	{
		$variable1=$row["EmployeeFName"];
		$variable2=$row["EmployeeLName"];
		$variable3=$row["EmployeeID"];
		$variable4=$row["EmployeeDepart"];
		$variable5=$row["EmployeeTeam"];
		$variable6=$row["ManagerID"];
		$variable7=$row["EmployeeTitle"]; 
if($variable3==$_POST['query'])
{
echo"<tr><td class='view'><form action='employee.html' method='post'><div><input type='submit' value='View' class='button' /></div></td><td name='userID' class='id'>{$variable3}</td></form><td name='userName' class='record'>{$variable1}{$space}{$variable2}  </td><td name='userTitle' class='record'>{$variable7}</td><td name='userTeam' class='record'>{$variable5}</td><td name='userDept' class='record'>{$variable4}</td></tr>";
}

	} 
}////her
	else
	{
		$Mangr= sqlQuery("SELECT * FROM Employee WHERE EmployeeFName like '$first' AND EmployeeLName like '$last'");
	while ($row = mysql_fetch_array($Mangr))
	{
		$variable1=$row["EmployeeFName"];
		$variable2=$row["EmployeeLName"];
		$variable3=$row["EmployeeID"];
		$variable4=$row["EmployeeDepart"];
		$variable5=$row["EmployeeTeam"];
		$variable6=$row["ManagerID"];
		$variable7=$row["EmployeeTitle"]; 
if($variable3==$_POST['query'])
{
echo"<tr><td class='view'><form action='employee.html' method='post'><div><input type='submit' value='View' class='button' /></div></td><td name='userID' class='id'>{$variable3}</td></form><td name='userName' class='record'>{$variable1}{$space}{$variable2}  </td><td name='userTitle' class='record'>{$variable7}</td><td name='userTeam' class='record'>{$variable5}</td><td name='userDept' class='record'>{$variable4}</td></tr>";
}

	} 
}

if (!$variable3)
{
print ("$XX");
exit('<p> Click <a href=search.php>here</a> to go back.</p>');
}

}
	}

but I cant get it to work!!
Can anyone help? PLEASE!!

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by R3Slick
0

I am modifying line 10 to 12.

$method=$_POST['searchType'];	
if ($method=='EmployeeId')
	$condition="(EmployeeId = '$search' or EmployeeFname = '$search')";
else
	$condition="$method = '$search'";
	
$search=$_POST['query'];	
$query = mysql_query("SELECT * FROM Employee WHERE $condition");
0

I am modifying line 10 to 12.

$method=$_POST['searchType'];	
if ($method=='EmployeeId')
	$condition="(EmployeeId = '$search' or EmployeeFname = '$search')";
else
	$condition="$method = '$search'";
	
$search=$_POST['query'];	
$query = mysql_query("SELECT * FROM Employee WHERE $condition");

I forgot to mention that by default when the user selects the manager option, it has name = "managerID" which is sent post which is the search type, since my table has EmpID, ManagerID, Fname, Lname, Team, Department.... I think i will just add a separate option on that menu if I cant get it...hopefully my teammates wont mind.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.